Question

Hi I want to use OR Condition in smarty please help me

{if $productgroup.gid neq '69' or
    $productgroup.gid neq '68'  or
    $productgroup.gid neq '27' or
    $productgroup.gid neq '31' or
    $productgroup.gid neq '70' or
    $productgroup.gid neq '71'}

    <select name="name" id="name" onchange="plan()">
        <option value="1">Car</option>
    </select>

{/if}
Was it helpful?

Solution

There should be no quotation between numeric during the if condition:

{if $productgroup.gid neq 69 or
    $productgroup.gid neq 68  or
    $productgroup.gid neq 27 or
    $productgroup.gid neq 31 or
    $productgroup.gid neq 70 or
    $productgroup.gid neq 71}

    <select name="name" id="name" onchange="plan()">
        <option value="1">Car</option>
    </select>

{/if}

OTHER TIPS

Instead of using OR, you can use in_array, which is shorter and easier to maintain:

{ if !in_array($productgroup.gid, array(69,68,27,31,70,71)) }
    <select name="name" id="name" onchange="plan()">
        <option value="1">Car</option>
    </select>
{/if}

Your code will always result in TRUE because a number is always not equal to either 69 or 68. If you are trying to check if the "gid" is no 27, 31, 68, 69, 70 or 71 then that needs to happen in a different way (in addition to the other answer about strings and numbers):

{if ! ( $productgroup.gid eq 69 or
        $productgroup.gid eq 68 or
        $productgroup.gid eq 27 or
        $productgroup.gid eq 31 or
        $productgroup.gid eq 70 or
        $productgroup.gid eq 71 ) }

    <select name="name" id="name" onchange="plan()">
        <option value="1">Car</option>
    </select>

{/if}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top