The right way to access Handlebars.helprs programatically


#1

A component might need to use different Handlebars.helpers based on the provided property.

What is the right way for accessing Handlebars.helpers pragmatically from a component and rendering the value correctly?


#2

This uses a view but the idea can still be applied to a component. There may be a better way of doing this, but this is my approach.

http://jsfiddle.net/NQKvy/707/


#3

Your solution is interesting and works rather well! However, I was more interested in how to call that actual method that is being registered with the helper.

From your example

Ember.Handlebars.helper('foo', function(value, options) {
  var escaped = Handlebars.Utils.escapeExpression(value);
  return new Handlebars.SafeString('foooo ' + escaped);
});

What is the way to access that function that we pass after ‘foo’. This function:

function(value, options) {
  var escaped = Handlebars.Utils.escapeExpression(value);
  return new Handlebars.SafeString('foooo ' + escaped);
}

#4

Ember.Handlebars.helpers.foo._rawFunction the underscore indicates you’re accessing a private… so tread lightly.

If you’re using EAK, you can always just import the helper function which is the approach I’ve taken in the past.


#5

Nice! That is exactly what I was looking for.

Since this is a discussion forum I’d like to ask if anyone knows the design decision behind making _rawFunction private and not exposing it to the public API.