Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ember.js context aware handlebars helper

Tags:

ember.js

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?

like image 335
dagda1 Avatar asked Jan 30 '26 11:01

dagda1


1 Answers

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.

like image 114
lulezi Avatar answered Feb 02 '26 03:02

lulezi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!