[Handlebars.js] Register custom helper methods with registerHelper

Tadashi Shigeoka ·  Wed, July 29, 2015

Handlebars.js can register custom helper methods using registerHelper.

For example, when you want to use the encodeURIComponent method in a template,

Handlebars.registerHelper('encodeURIComponent', encodeURIComponent);

register the helper like this, and

{{encodeURIComponent 'http://tryhandlebarsjs.com/'}}

write it in the template, then

http%3A%2F%2Ftryhandlebarsjs.com%2F

HTML like this will be output.

When the helper is no longer needed,

Handlebars.unregisterHelper('encodeURIComponent');

you can unassign it.


Reference Information

That’s all from the Gemba.