create-html-template-element

Create an HTML <template> with content.

Usage no npm install needed!

<script type="module">
  import createHtmlTemplateElement from 'https://cdn.skypack.dev/create-html-template-element';
</script>

README

create-html-template-element NPM Version Build Status

Create an HTML <template> with content.

Installation

Node.js >= 10 is required. To install, type this at the command line:

npm install create-html-template-element

Importing

ES Module:

import html from 'create-html-template-element';

CommonJS Module:

const html = require('create-html-template-element');

Usage

As a tagged template literal:

const TEMPLATE = html`
  <elm attr="val">txt</elm>
`;
//-> HTMLTemplateElement

As a regular function:

const TEMPLATE = html(`
  <elm attr="val">txt</elm>
`);
//-> HTMLTemplateElement

With custom document (useful for jsdom):

const TEMPLATE = html(`<elm attr="val">txt</elm>`, iframe.contentWindow.document);
//-> HTMLTemplateElement