Skip to content
Advertisement

Logical operator in a handlebars.js {{#if}} conditional

Is there a way in handlebars JS to incorporate logical operators into the standard handlebars.js conditional operator? Something like this:

JavaScript

I know I could write my own helper, but first I’d like to make sure I’m not reinventing the wheel.

Advertisement

Answer

This is possible by ‘cheating’ with a block helper. This probably goes against the Ideology of the people who developed Handlebars.

JavaScript

You can then call the helper in the template like this

JavaScript
Advertisement