Handlebars: multiple conditions IF statement?

32,715

Solution 1

They do not have multiple conditions. But you can achieve it by nesting. This works:

{{#if A}}
   {{#if B}}
     {{#if C}}
       something 
    {{/if}}
   {{/if}}
{{/if}}

Solution 2

What about this?

{{#if A}}
  something
{{else if B}}
  someting B
{{else if C}}
  someting C
{{/if}}

Solution 3

in 3.0 you can do it with

{{#if A}}
  something
  {{else if B}}
    something
    {{else if C}}
      something
    {{/if}}
  {{/if}}
{{/if}}

if you use something below 3.0 you can make multiple ifs

{{#if A}}
{{else}}
  {{#if B}}

... and so on hope this helps

Share:
32,715
zwiebl
Author by

zwiebl

Updated on July 09, 2022

Comments

  • zwiebl
    zwiebl almost 2 years

    I didn't find this was possible in Handlebars... I need something like this:

    {{#if A || B || C}} something {{/if}}
    

    Is that possible to achieve? I have looked at this answer, but as I need for 3 variables (A, B, C) I don't really know how to apply it. Any ideas?