leshill / handlebars_assets

Use handlebars.js templates with the Rails asset pipeline.
MIT License
647 stars 159 forks source link

Adding helpers #47

Closed peregrinator closed 11 years ago

peregrinator commented 11 years ago

I'm sure this is something simple but I haven't been able to figure this out quickly so it might be worth a mention in the README or docs somewhere.

How does one register a helper to be used with templates?

Thanks!

leshill commented 11 years ago

Hi @peregrinator,

You should do so in a .js (or .coffee) file. For example, in Rails, you might just add the registration of helpers directly to application.js or one of the files it pulls in.

The flow of JS should be something like this:

  1. load libraries, like Handlebars
  2. perform global inits (helper registration goes here)
  3. application init

After registration, the helper is available to all your templates.

Does that help?

peregrinator commented 11 years ago

Apparently I need to go to bed. That works great for me now, sorry for the trouble - I was sure there was something I was missing!