Blaze Spacebar IF to match Helper return String

In Blaze Spacebar, is it possible to have if condition similar to IF in javascript for matching helper return string to decide to show the block or not to show.

Such as

{{#if helpername=='red'}}
    <h1>Show if helper return match red</h1>
{{/if}}

Please advice, thanks.

Only through the use of another helper.

As an example, you could add a global helper like so:

Template.registerHelper('compare', function(arg1, arg2) {
  return arg1 == arg2
});

That will allow you to compare

{{#if compare helpername 'red' }}
    <h1>Show if helper return match red</h1>
{{/if}}

Or if you’re happy with lisp dialects:

Template.registerHelper('==', (arg1, arg2) => arg1 == arg2 );
{{#if == helpername 'red' }}
    <h1>Show if helper return match red</h1>
{{/if}}
2 Likes

Thanks so much. I’ll try this method. Appreciate.