Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 412
zwiebl Avatar asked Dec 20 '16 21:12

zwiebl


People also ask

Is there else if in Handlebars?

Handlebars supports {{else if}} blocks as of 3.0. 0. is the point in not having an elsif (or else if) in handlebars that you are putting too much logic into your template.

Can you have multiple conditions in an if statement JavaScript?

You can use the logical AND (&&) and logical OR (||) operators to specify multiple conditions in an if statement. When using logical AND (&&), all conditions have to be met for the if block to run.

How do you iterate objects in Handlebars?

To iterate over an object with JavaScript and Handlebars. js, we can use the #each keyword. to add the Handlebars script and the template for looping through each entry in data . We use #each this to loop through each array property.


2 Answers

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}} 
like image 70
Harsha Vardhini Avatar answered Sep 20 '22 23:09

Harsha Vardhini


What about this?

{{#if A}}   something {{else if B}}   someting B {{else if C}}   someting C {{/if}} 
like image 32
Mario Mixtega Avatar answered Sep 17 '22 23:09

Mario Mixtega