0.3.3 • Published 11 years ago
underscore-tpl v0.3.3
underscore-tpl
_.templatefor objects
Installation
Bower
bower install underscore-tplNpm
npm install underscore-tplUsage
API
_tpl( subject, values, [settings])Example
var _tpl = require( 'underscore-tpl' );
var values = {
foo : "foo",
badass : "Jules Winfield",
qux : {
mofo : "mofo"
}
};
var config = {
baz : "<%= qux.mofo %>",
major : {
badass : "<%= badass %>"
},
"<%= foo %>" : "bar"
};
console.log( _tpl( config, values ) );# output
{ baz: 'mofo', major: { badass: 'Jules Winfield' }, foo: 'bar' }Settings
_tpl accepts all _.template settings and adds a few more:
ignoreKeysBoolean: whentrueobject keys will not be interpolated. (Default:false)mustache|handlebarsBoolean: whentrueyou can use mustache style tags{{ }}instead of ERB.
These can be set either in the settings parameter of _tpl, e.g.:
var results = _tpl(subject, values, {
ignorekeys: true
});or globally:
_tpl.templateSettings.ignoreKeys = true;License
Released under MIT license