Nested handlebars helpers weird behaviour


#1

Hello!

I’ve started writing my first Ember project. I am using Ember.js 1.9.1 and Handlebars 2.0.0, but I’ve already ran into suprising behaviour when nesting custom helpers.

According to handlebars doc syntax for nesting is following:

{{orange (apple "test")}}

When I define my helpers as such:

Ember.Handlebars.helper('apple', function(value) {
  return 'apple(' + value + ')';
});

Ember.Handlebars.helper('orange', function(value) {
  return 'orange(' + value + ')';
});

It’s rendered like this:

apple(test)orange(undefined)

When I register them as such:

Ember.Handlebars.registerBoundHelper('apple', function(value) {
  return 'apple(' + value + ')';
});

Ember.Handlebars.registerBoundHelper('orange', function(value) {
  return 'orange(' + value + ')';
});

Also produces invalid output:

apple(test)orange(undefined)

Finally when I register them using registerHelper they suddenly start working:

Ember.Handlebars.registerHelper('apple', function(value) {
  return 'apple(' + value + ')';
});

Ember.Handlebars.registerHelper('orange', function(value) {
  return 'orange(' + value + ')';
});

Renders:

orange(apple(test))

I would be very grateful for explanation what I am doing wrong.


#2

Custom nested helpers are not supposed in Ember 1.9. They are possible in Ember 1.10 with HTMLBars though.


#3

I guess for now I’ll go around this limitation via moving part of i18n into controllers then.

Allright, thanks.


#4

I’ve looked HTMLBars up and I like what I see, but I’m wondering. Does this means bound/unbound difference will go away as well, or will be reduced to “updated”/“static”?


#5

bound and unbound still work the same way.


#6

humm… let me ask differently then?

To my understanding bound expressions are wrapped around in script element and unbound are not. So wrapped things can be updated and unwrapped things don’t because after Ember renders them, it loses idea where they were.

With HTMLBars neither bound and unbound expressions are wrapped with script, so I can put bound expression directly into html element, but if I know that data behind expression will never change, I can use unbound helper for little speed up?

I am getting this right?


#7

Yes, that’s correct.