Wrap underscore.string functions to Handlebars helpers
Via bower
:
bower install handlebars-helpers-underscore.string
Via npm
:
npm install handlebars-helpers-underscore.string
In node
:
Handlebars = require('handlebars');
require('handlebars-helpers-underscore.string');
var source = "<p>Hello, my name is {{name}}. I am from {{underscored hometown}}. I have " +
"{{kids.length}} kids:</p>" +
"<ul>{{#kids}}<li>{{name}} is {{age}}</li>{{/kids}}</ul>";
var template = Handlebars.compile(source);
var data = { "name": "Alan", "hometown": "Somewhere, TX",
"kids": [{"name": "Jimmy", "age": "12"}, {"name": "Sally", "age": "4"}]};
var result = template(data);
// Would render:
// <p>Hello, my name is Alan. I am from somewhere,_tx. I have 2 kids:</p>
// <ul>
// <li>Jimmy is 12</li>
// <li>Sally is 4</li>
// </ul>
In webpack
remember to set node.fs
to empty
.