I have a scenario where I am getting {{isdone}}
value with Boolean data.
I want to be printed as "pending" for false
value and "Done" for true
.
I'm using below code, Which isn't working.
{{isdone}} == false ? "pending" : "Done"
I have a scenario where I am getting {{isdone}}
value with Boolean data.
I want to be printed as "pending" for false
value and "Done" for true
.
I'm using below code, Which isn't working.
{{isdone}} == false ? "pending" : "Done"
^
block for else.You can (now) use the ^
block for an else
or false
condition. Something like this should work:
{{#isdone}}Done{{/isdone}}{{^isdone}}pending{{/isdone}}
Or as a more readable multi-line block of code:
{{#isdone}}
Done
{{/isdone}}
{{^isdone}}
pending
{{/isdone}}
As long as you have control of your context data, correct way is to pass another variable, that will already contain pending
or Done
beforehand.
If you don't have control over the data, then maybe moustache isn't good for you as you may need template engine that can have some more logic in it to transform data a bit.
You might want to register a ternary
helper for that
Handlebars.registerHelper("ternary", function (condition, trueValue, falseValue, options) {
return condition ? trueValue : falseValue;
});
and then in your templates use it like
{{ternary isdone "Done" "pending"}}