Search code examples
htmlsmarty

smarty 'OR' operator is not working?


{if $command2 ne "thanks" || $command1 ne "error"}
 some code <!---Ist Code-->
{/if}

{if $command2 eq "thanks" || ($command1 eq "error"}
<meta name="Robots" content="noindex, nofollow"> <!---2nd Code-->
{/if}

I am trying this but its not working.its showing both 1st and 2nd code Give me one solution


Solution

  • I think your problem is with logic. Try && operator with ne case like;

    {if $command2 ne "thanks" && $command1 ne "error"}
     some code <!---Ist Code-->
    {/if}
    
    {if $command2 eq "thanks" || ($command1 eq "error"}
    <meta name="Robots" content="noindex, nofollow"> <!---2nd Code-->
    {/if}
    

    it's a basic programming knowledge. when you invert the case, invert ORs to ANDs, too.

    Keep in mind that depending on your needs, it might be vice versa like;

    {if $command2 ne "thanks" || $command1 ne "error"}
     some code <!---Ist Code-->
    {/if}
    
    {if $command2 eq "thanks" && ($command1 eq "error"}
    <meta name="Robots" content="noindex, nofollow"> <!---2nd Code-->
    {/if}
    

    Both makes sense in different scenerios.

    Update: After your second comment, it's clear that you need the first example at the top.