In my plugin, I want to have an if
statement in a template, that evaluates whether a string matches a value.
Like this:
{{#each groups as |group|}}
{{#if group.name === "AwesomeName"}}
<div>There is a match!</div>
{{/if}}
{{/each}}
How can I do this in Discourse?
I understand that doing a straight {{if}} does not work in Ember/Handlebars. It looks like I have to register a helper. Something like this:
plugin/assets/javascripts/discourse/helpers/eq/js/es6
import { registerHelper } from 'discourse-common/lib/helpers';
registerHelper('eq', function(arg1, arg2) {
if (arg1 === arg2) {
return true
} else {
return false
}
})
plugin/assets/javascripts/templates/components/my-component.hbs
{#each groups as |group|}}
{{#eq group.name "AwesomeName"}}
<div>There is a match!</div>
{{/eq}}
{{/each}}
This doesn’t work. (There are no errors provided.)
I tried the solution here, which tries to use “makeBoundHelper”, but it doesn’t work for me either–there I get errors about “makeBoundHelper” is not a function.
I just want to be able to do an if statement for matching a string to a value. How do I do it?