Underscore template pipe
An underscore template function that can return json.
What's it do?
Adds an additional behavior to Underscore templating called pipe
, which does everything that the =
interplator does except it doesn't coerce variables to strings — it returns them as whatever type they are.
Use <%| name %>
syntax.
The normal <%= name %>
, <%- name %>
and <% name %>
tags behave exactly as they do in underscore.
Usage
As an underscore function in NodeJS
var _ = _templatePipe = var templateString = _ data: authors: name: 'mhk' name: 'khm' // => [ { name: 'mhk' }, { name: 'khm' } ]
On its own
var templatePipe = var templateString = data: authors: name: 'mhk' name: 'khm' // => [ { name: 'mhk' }, { name: 'khm' } ]
With a custom syntax style
var templatePipe = var templateSettings = evaluate : /<%%>/g interpolate : /<%=%>/g escape : /<%-%>/g pipe : /<%~%>/g // Use a `~` instead of `|`. The other settings need not be specified if they are not modified. Listed here to show options. var templateString = data: authors: name: 'mhk' name: 'khm' // => [ { name: 'mhk' }, { name: 'khm' } ]
License
MIT