dagda1
dagda1

Reputation: 28770

ember.js context aware handlebars helper

I have code like this that I am going to repeat a lot:

<div>
  {{#if sender.isContact}}
  <a {{action showContact sender href=true}}>{{unbound sender.displayName}}</a>
  {{else}}
    <a {{action showUser sender href=true}}>{{unbound sender.displayName}}</a>
  {{/if}}
</div>

THe only bit that changes is the action that the will be called.

How would I create a handlebars helper method to dry this up?

Upvotes: 3

Views: 543

Answers (1)

lulezi
lulezi

Reputation: 831

The creation of custom helpers is described pretty well in the Templates section of the Ember.js Guides.

You can also have a look at how the {{action}} helper in the Code and merge the parts you need for your own helper.

Upvotes: 3

Related Questions