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 }}Written by Matthew Rudy Jacobs
Related protips
1 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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
 #Handlebars 
Authors
 
wern
18.84K
 
benjaminrh
10.05K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#

