user6375350 user6375350 - 2 months ago 6
PHP Question

How to check double condition smarty

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

Answer

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: http://www.smarty.net/docs/en/

eq is an alias of == which you can see here: http://www.smarty.net/docs/en/language.function.if.tpl

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:

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

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