ut

underscore-tpl

_.template for objects

Showing:

Popularity

Downloads/wk

3

GitHub Stars

26

Maintenance

Last Commit

7yrs ago

Contributors

0

Package

Dependencies

1

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

underscore-tpl

_.template for objects

Installation

Bower

bower install underscore-tpl

Npm

npm install underscore-tpl

Usage

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:

  • ignoreKeys [Boolean]: when true object keys will not be interpolated. (Default: false)
  • mustache|handlebars [Boolean]: when true you 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

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial