I want to compare two values in the handlebar template. This cannot be done using {{#if}} helper. So how can I create a new helper in Discourse?
I have tried below code but not working:
Created FIle: /assets/javascripts/discourse/helpers/eq.js.es6
import { registerHelper } from 'discourse-common/lib/helpers'
var makeBoundHelper = Ember.HTMLBars.makeBoundHelper;
registerHelper('eq', makeBoundHelper(function(params) {
return params[0] === params[1];
}));
Throwing Exception: makeBoundHelper is not a function
It’s just EmberJS, use a Computed Property.
I want to achieve somewhat like below:
have two each loop
- productCategories : [“category1”, “category2”, …]
- productTags : [{productCategory:“category1”, tagName:“tag1”, isChecked:true}, …]
And now i want to compare productCategories items with tag.productCategory as shown in code.
Can we achieve this by Computed properties?
<div class="tag-list-section">
{{#each this.productCategories as |category|}}
<div id={{category}} class="select-tag-category">
{{#each this.productTags as |tag|}}
{{#if (eq category tag.productCategory)}}
{{input type="checkbox" name=tag.tagName checked=tag.isChecked }} {{tag.tagName}}
{{/if}}
{{/each}}
</div>
{{/each}}
</div>