html-template
build templates with ordinary html for node and browsers
Write plain html and use css selectors to modify the html.
example
Put template=
attributes on the elements you want to turn into templates.
Here we'll make a template called "skill"
on a <tr>
:
list of skillsskill nameskill level
in node
In node we can do:
var template = ;var fs = ;var html = ;var skills = html;fs;skills;skills;skills;skills;
to produce:
list of skillsskill nameskill levelmacaroni pictures40%quilting5000%blinky lights50%
in browsers
In the browser, do:
var html = ;var skills = html;skills;skills;
and new elements will be generated dynamically.
node methods
var template = require('html-template')
var html = template()
Create a new html template stream html
that takes html input with template
attributes and produces html output with expanded template data.
var t = html.template(name, opts)
Load a template t
by its template name
in the html.
Optionally:
opts.include
- whenfalse
, do not include the original template in the html output. Otherwise include the original template withstyle="display:none"
so the template can be loaded in the browser to create additional output.
t.write(row)
Write row
, an object mapping css selector keys to
hyperglue-style values,
to the output stream.
browser methods
var template = require('html-template')
var streamTemplate = require('html-template/stream')
var html = template()
Create a new html
instance.
var t = html.template(name)
Load a template t
by its template name
in the html.
t.write(row)
Write a hyperglue-style object mapping css selectors to attributes and content to the page.
var elem = t.create(row)
Create a hyperglue-style object mapping
without inserting the element elem
to the DOM.
var html = streamTemplate()
Create an html
that will create real stream template (t
)s.
install
With npm do:
npm install html-template
license
MIT