Search code examples
node.jstemplatesexpresshandlebars.js

How to use equality in handlebars build-in #if helper


In handlebars how can I say for example:

{{#if view_type == "medium"}}
    // Do something
{{/if}}

Not simply :

{{#if view_type}}
    // Do something
{{/if}}

Im am using it in NodeJs

Im looking for solution without registerHelper()


Solution

  • There's no solution without a new helper. What I would suggest you is to switch from handlebars to Swig, which, the syntax, is pretty similar.

    http://paularmstrong.github.io/swig/docs/

    It is easily implementable.

    If you are trying to do an IF I guess you are at the beginning of your project so it could be an option.