user6375350
user6375350

Reputation: 95

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

Upvotes: 0

Views: 650

Answers (7)

user6375350
user6375350

Reputation: 95

In the end, the error was located in the id section. When having several sections and using the same id can result in an error. To solve this I used classes instead like this:

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

And changed the javascript from # to .

Once done that the double if statement works fine.

Upvotes: 0

Mikey
Mikey

Reputation: 2704

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.

Upvotes: 2

Oposyma
Oposyma

Reputation: 129

If you are using smarty try this

{if ($nvTb eq 1) || ($nvTb eq 2)}
    do something
{/if}

In your case

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

Upvotes: 1

MounirOnGithub
MounirOnGithub

Reputation: 699

You may try this :

<?php 
switch($nvTb) {
    case 1:
        //your code here
    case 2:
        //your code here
}

Upvotes: 1

Patrick Mlr
Patrick Mlr

Reputation: 2965

That looks like Smarty. Try it like this:

{if $nvTb == 1 || $nvTb == 2}

Cheers.

Upvotes: 1

B.G.
B.G.

Reputation: 6016

There is no "eq" in php just use == ->

if ($nvTb == 1 || $nvTb == 2)

Note: There is also a typesafe compare in php === For more Infos look here http://php.net/manual/en/language.operators.comparison.php#language.operators.comparison

Upvotes: 0

Vivek Singh
Vivek Singh

Reputation: 2447

in php you can do something like this

<?php if(($nvTb == 1) ||  if($nvTb == 2)) {


}?>

Upvotes: 1

Related Questions