I have a custom helper, as follows:
Handlebars.registerHelper('hasAccess', function(val, fnTrue, fnFalse) {
return val > 5 ? fnTrue() : fnFalse();
});
and my template, as follows:
{{#hasAccess this.access}}
You have access!
{{else}}
You do not have access
{{/hasAccess}}
It works, except fnFalse is undefined. So, how am I supposed to render the ‘else’ branch?
Handlebars provides custom helpers an object containing the different functions to apply,
options.fnandoptions.inverse. See https://handlebarsjs.com/guide/block-helpers.html#conditionalsYour helper could be written as
And a demo