HTMLBars custom helper


#1

Hi!

For me, yesterday was day one of using Ember seriously (in the past i’ve built a couple very trivial hello world apps).

I’m trying to create a custom template helper. Any idea why the linked code isn’t working as I’d expect? I’m trying to send the model (which contains an array) to a helper that should join the array elements together as a string, but instead I get the literal string “model”.

http://jsbin.com/pizane/2/edit?html,js,output

Looking over the sample templates on the handlebars site, this should work. (I know that handlebars != htmlbars, but I had thought that htmlbars was able to grok a handlebars template.)


#2

I think I got it fixed for you.

Here, try this out: http://jsbin.com/pepela/1/edit?html,js,output


#3

Awesome!

I guess I needed Ember.Handlebars.registerBoundHelper instead of Ember.Handlebars.registerHelper

Whats the purpose of Ember.Handlebars.registerHelper (I’m not certain what lead me to believe I wanted registerHelper). Looking at the API (http://emberjs.com/api/classes/Ember.Handlebars.html) I don’t see registerHelper listed. That said there are handful of links in the API that have ‘handlebars’ and ‘htmlbars’ as part of their title and its not clear to me which one(s) I should care about.

All the same. Thanks for getting me unstuck!!


#4

Ok I know where I got registerHelper from. This issue about creating a custom ‘join’ helper. Clearly it was written pre-htmlbar days.


#5

Handlebars.registerHelper is a legit method, but it belongs to Handlebars proper. Also, there’s some utility behind registerBoundHelper inside Ember that wires up binding, where the plain registerHelper in the Handlebars library wouldn’t.

Hope that makes some sense.