wusher wusher - 8 months ago 23
Node.js Question

How do you register a custom helper if you are precompiling a custom helper in Handlebars.js?

I am trying to precompile a Handlebars.js template

with the command
handlebar app/views/templates/walrus.handlebar
but it fails because the template uses a custom helper that I have defined in a seperate js file

How do I call the command line version of Handlebars so it is aware of the javascript file with the custom helper?

handlebars <input> -f <output> -k <helper>

It's in the docs here: http://handlebarsjs.com/precompilation.html

Edit March 2014:

For people having issues reading the docs, here's an example for custom helper "fullname"

handlebars myTemplate.handlebars -f handlebars-fullname.js -k fullname

with this helper:

Handlebars.registerHelper('fullname', function(person) {
  return person.firstName + " " + person.lastName;

You still have to include the helper in the page with the handlebars.runtime.js