Lightweight collection of useful handlebars helpers for the browser or server.
bower install gb-handlebars-helpers
npm install gb-handlebars-helpers
Register the helpers:
var Handlebars = require('handlebars');
var helpers = require('gb-handlebars-helpers');
// register all the helpers
helpers.register(Handlebars);
// or cherry pick what you need
helpers.register(Handlebars, ['truncate', 'dollars']);
Using helpers:
// use a helper directly
console.log(Handlebars.helpers.dollars(234)); // '2.34'
// or in a template
var templateStr = 'You balance: ${{dollars amount}}';
var template = Handlebars.compile(templateStr);
var output = template({ amount: 234 }); // 'Your balance: $2.34'
Register all helpers
Register with a list of helper names
Register helpers by passing in parameters
Unregister using same signatures as .register
- eq
- dneq
- lt
- lte
- gt
- gte
- add
- subtract
- multiply
- divide
- intDivide
- mod
- truncate
- capitalize
- uppercase
- lowercase
- dollars
- pennies
- datepart
- timepart
- formatDatetime
Bolded helpers can be used for conditional templating blocks.
For example:
MIT