zwiebl
zwiebl

Reputation: 725

Handlebars: multiple conditions IF statement?

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?

Upvotes: 36

Views: 52994

Answers (3)

Gabriel
Gabriel

Reputation: 89

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

Upvotes: 2

Mario Mixtega
Mario Mixtega

Reputation: 116

What about this?

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

Upvotes: 7

Harsha Vardhini
Harsha Vardhini

Reputation: 732

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}}

Upvotes: 37

Related Questions