user6375350 user6375350 - 1 month ago 4
Smarty Question

How to check double condition PHP

I want to check if the variable $nvTb is 1 or 2.

I'm doing this but not working

{if (($nvTb eq 1) or ($nvTb eq 2)) }

to achieve something like this

<a role="tab" {if (($nvTb eq 1) or ($nvTb eq 2)) } id="fichaScroll" {else} data-toggle="tab" {/if}>

When I run the code with only one if check like

{if $nvTb eq 1}

then works


I'm guessing that TPL was meant to be for smarty templates judging by the syntax which you can get the full documentation from here:

eq is an alias of == which you can see here:

In terms of your problem, try the following:

<a role="tab" {if $nvTb === 1 || $nvTb === 2} id="fichaScroll" {else} data-toggle="tab" {/if}>

eq is an alias of == so that means that it will treat 1 as true, meaning that anything that any truth-ee value will also pass the check. I'm guessing that might be your problem.

If that isn't the problem try the following:

echo '<a role="tab" ((if $nvTb === 1 || $nvTb === 2) ? id="fichaScroll" 
                                                     : data-toggle="tab")>';

Not the prettiest solution by any means but I believe it should work.