Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spacebars: how to use and / or in if statements

I have following code:

 <div class="form-group {{#if afFieldIsInvalid name='latitude' OR name='longitude'}}has-error{{/if}}">......</div>

How can I use AND/OR in if conditions of spacebars templates ?

like image 261
Simpanoz Avatar asked Feb 10 '15 08:02

Simpanoz


1 Answers

Spacebars can't handle logical expressions, so you need to create a helper handling the calculations for you.

Actually, you can achieve and functionality with nested ifs like this:

{{#if condition1}}
    {{#if condition2}}
        <p>Both condition hold!</p>
    {{/if}}
{{/if}}

And or like this:

{{#if condition1}}
    <p>One of the conditions are true!</p>
{{else}}
    {{#if condition2}}
        <p>One of the conditions are true!</p>
    {{/if}}
{{/if}}

But I would prefer using a helper.

like image 64
Peppe L-G Avatar answered Oct 27 '22 08:10

Peppe L-G