2

Let's say, I would like to call an Ember Handlebars helper from an emblem.js template.

I have declared the helper through (CoffeeScript syntax):

Ember.Handlebars.registerHelper 't', (key, value, context) ->
    ...

When attempting to invoke the helper from emblem using

= t "my.i18n.key", "val", count: 42

key is assigned correctly, all but the first arguments are dropped and the second argument is replaced by some options hash as would be the case for a bound helper (the third argument is undefined).

Is there any way to invoke a helper in emblem.js with more than a single argument?

Thilo-Alexander Ginkel
  • 6,898
  • 10
  • 45
  • 58

1 Answers1

4

I think you can only pass one value, but you can use the options hash with many bound/computed properties like this:

Ember.Handlebars.registerBoundHelper('truncatedQuery', 
  function truncatedQueryHelper(value, options) {
    console.log('value', value, 'options:', 
      options.hash['key1'], options.hash['key2'], options.hash['key3']);
  // do work...
   return somethingUseful;
});

And in your template use optionsHashKeyBinding=propertyOnControllerName like this:

<div class='truncated-query'>
  {{truncatedQuery 'value' key1Binding=prop1 key2Binding=prop2 key3=42}}
</div>

Where prop1 and prop2 are on the controller:

App.IndexController = Ember.Controller.extend({
  prop1: 'foo',
  prop2: function() {
    return this.get('prop1') + 'bar';
  }.property('prop1'),
});
Robert Carter Mills
  • 793
  • 1
  • 9
  • 19