I have the following custom Handlebars helper:
Handlebars.registerHelper('IsNewUser', function (userId) {
return (userId < 1);
});
And the following HTML in my view:
{{#IsNewUser Id}}
<div>
<input name="IsActive" id="user-active" type="checkbox" checked />
Active
</div>
{{/IsNewUser}}
I can clearly see the function being hit, the userId
parameter passed correctly, and the return is true
of type bool but instead of showing the block it shows the text 'true'.
How can I get the HTML block to hide with Handlebars without error'ing out?
I was able to fix it after gaining some insight from this StackOverflow question . Changed my helper method to the following:
Handlebars.registerHelper('IsNewUser', function (userId, options) {
if (userId < 1)
return options.fn(this);
else
return options.inverse(this);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.