问题
This is my code in smarty:
{if $cat!="1_5"} do something {/if}
If I add additional condition with or
:
{if $cat!="1_5" or $cat!="2_30"} do something {/if}
Then it doesn't work in proper way. Why? Is this possible to use in one brackets two or more inequality conditions?
回答1:
Alright, so we have the categories 1_5 and 2_30
let's see what happens in your if-condition when $cat="2_30"
$cat!="1_5" $cat!="2_30" $cat!="1_5" $cat!="2_30"
| | | |
TRUE FALSE TRUE FALSE
\ / \ /
\ / but: \ /
\ / \ /
OR AND
| |
TRUE FALSE
//do something //don't do something
So, you get the idea :) You have to use AND
instead of OR
:
{if $cat!="1_5" and $cat!="2_30"} do something {/if}
来源:https://stackoverflow.com/questions/7525722/smarty-two-or-more-inequality-conditions-in-one-bracket