leshill / handlebars_assets

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

Add helper with the handlebars.runtime #120

Closed cbou closed 1 year ago

cbou commented 9 years ago

I didn't find any way to include helpers when using the handlebars.runtime.

AlexRiedler commented 9 years ago

@cbou is this in regards to this gem, or you mean on the javascript side.

The javascript of handlebars.js is here: http://handlebarsjs.com/reference.html

you should be able to do Handlebars.registerHelper('name', func)

cbou commented 9 years ago

I means in this gems yes.

When I use //= require handlebars.runtime, I don't have the chance to inject helpers before it's compile right?

AlexRiedler commented 9 years ago

@cbou it is actually possible to inject by overriding:

I am not sure if there is any documentation about this feature, but it is in there (alpha).

mattboon commented 9 years ago

@AlexRiedler I'm trying to add a server-side helper I'm using in my js via Handlebars.registerHelper. Any code example to implement the above on first load?

Thanks

AlexRiedler commented 9 years ago

@mattberridge finally got around to it: https://github.com/AlexRiedler/hbs_examples/tree/helper-example

this is without the additional optimization of knownHelpers