Answered
How do I show an element in my handlebars (.hbs
) only if it's not true
.
I've tried to do {{#if not}}
, {{#!if}}
, {{#if !condition}}
. But those don't work.
Any ideas?
I'm currently just doing:
{{#if condition}}
{{else}}
<button>Submit</button>
{{/if}}
And am looking to simplify it to not use the if...else
statement.
You're looking for the {{#unless}} helper. It serves as the inverse of the if
helper you're attempting to use.
You could use it like this in your Handlebars code:
{{#unless condition}}
<button>Submit</button>
{{/unless}}
This would show the <button>
element when the condition
you provide to the helper is falsey. Otherwise, it would render nothing.