Skip to content

tomi77/handlebars-helpers-underscore.string

Repository files navigation

Build Status Coverage Status Code Climate Dependency Status devDependency Status peerDependency Status Downloads

handlebars-helpers-underscore.string

Wrap underscore.string functions to Handlebars helpers

Installation

Via bower:

bower install handlebars-helpers-underscore.string

Via npm:

npm install handlebars-helpers-underscore.string

Usage

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.

About

Wrap underscore.string functions to Handlebars helpers

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published