Last Updated: February 25, 2016
·
2.28K
· matthewrudy

Ember helpers with options

To create a regular helper is simple;

Ember.Handlebars.helper 'gravatar', (user) ->
  # build a gravatar tag with size 20
  ...

, 'gravatarUrl'

We can now call this with a user model;

{{ gravatar currentUser }}

However, we've hardcoded the size of the gravatar.

If we want to take in optional arguments (as of Ember 1.0.0.rc6) we need to do the following

Ember.Handlebars.helper 'gravatar', (user, options) ->
  size = options.hash.size || 20

  # build our gravatar tag using "size"
  ...

, 'gravatarUrl'

We can then call this in handlebars

{{ gravatar currentUser size=40 }}

1 Response
Add your response

Hi, thanks for the tip, but I had one problem. When I tried to pass like this:

{{#with controllers.currentCardCategory}} {{#each property in cardProperties}} <td class="td">{{cardProperty this property=property.symbol}}</td> {{/each}} {{/with}}

(this is a Card record)
I got the string property.symbol' but when I passed it as{{cardProperty this propert.symbol` it works. Do you have any idea what's going on?

over 1 year ago ·