smarty - two or more inequality conditions in one bracket?

跟風遠走 提交于 2019-12-11 00:25:33

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!