Reputation: 189
I wrote the below if else condition in handlebars template but every time its going in else part even my emps.marital_status value is married.
{{#if ('emps.marital_status "married"') }}
married
{{else}}
unmarried
{{/if }}
Upvotes: 0
Views: 1016
Reputation: 2844
Handlebars does not support equality check in if
blocks. You need register your own helper:
handlebars.registerHelper('ifvalue', function (conditional, options) {
if (options.hash.value === conditional) {
return options.fn(this)
} else {
return options.inverse(this);
}
});
And use it:
{{#ifvalue emps.marital_status value="married"}}
married
{{else}}
unmarried
{{/ifvalue}}
Upvotes: 1