How do you register a user assistant if you precompile a user assistant in Handlebars.js?

I am trying to precompile the Handlebars.js app/views/templates/walrus.handlebar with the handlebar app/views/templates/walrus.handlebar , but it fails because the template uses the custom helper that I defined in a separate js public/javascripts/handlebar_helpers.js file public/javascripts/handlebar_helpers.js .

How do I call the Handlebars command line version so that it knows about the javascript file with a user helper?

+7
source share
2 answers
 handlebars <input> -f <output> -k <helper> 

In the following documents: http://handlebarsjs.com/precompilation.html

Edit March 2014:

For people who have problems reading documents, here is an example of a custom helper "full name"

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

using this helper:

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

You still need to enable the helper on the page using handlebars.runtime.js

+5
source
 handlebars myTemplate.handlebars -f handlebars-fullname.js -k fullname 

The above step is optional. , your steering pattern would work even if you did not specify the name of the helper during pre-compilation, however the following code (which should basically contain all your helpers) needs to be inserted on the client side

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

I tried this and it works like a charm!

0
source

All Articles