inject-template
Inject template into innerHTML
Installation
$ npm install --save inject-template
Usage
- An template tag in the desired element 1
- An html template 2
var injectTemplate = ; let result = injectTemplate // injects content from rainbow.html// dosomething with result ...
result
{ super; thisinnerHTML = 'BIG RAINBOW'; } ...
rainbow.js 1
{ super; // @template rainbow } ...
rainbow.html 2
BIG RAINBOW
Named templates
var injectTemplate = ; let result = injectTemplate // injects content from rainbow-template.html
Custom templates path
var injectTemplate = ; let result = injectTemplate // injects content from templates/rainbow.html
API
injectTemplate.inject({options})
injectTemplate.injectSync({options})
options
path
Type: string
Default: null
Path to file containing the template tag
templatePath
Type: string
Default: null
Path to the template (use when your template is in another directory).
When undefined inject-template assumes the template in in the same directory of the element
content
Type: string
Default: null
The content of the element (used in gulp-inject-html-template)
When streaming files, you can pass trough the content so inject-template doesn't need to read the element.
License
MIT © Glenn Vandeuren