handlebars_assets icon indicating copy to clipboard operation
handlebars_assets copied to clipboard

Add helper with the handlebars.runtime

Open cbou opened this issue 10 years ago • 5 comments

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

cbou avatar Feb 21 '15 20:02 cbou

@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)

AlexRiedler avatar Feb 22 '15 18:02 AlexRiedler

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?

cbou avatar Feb 22 '15 20:02 cbou

@cbou it is actually possible to inject by overriding:

  • the compiler
  • the compiler path
  • the known_helpers

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

AlexRiedler avatar Feb 23 '15 01:02 AlexRiedler

@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

mattboon avatar Feb 23 '15 11:02 mattboon

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

this is without the additional optimization of knownHelpers

AlexRiedler avatar Mar 01 '15 22:03 AlexRiedler