How can I use multiple operands in an if condition (ModX)

为君一笑 提交于 2019-12-12 04:06:12

问题


I am using the if-extra for ModX. Is it possible to use mutliple operands, meaning write this code in a shorter way:

  [[!If?
       &subject=`[[!getUrlParam? &name=`id`]]`
       &operator=`EQ`
       &operand=`1`
       &then=`do something`
    ]]


[[!If?
   &subject=`[[!getUrlParam? &name=`id`]]`
   &operator=`EQ`
   &operand=`2`
   &then=`do something`
]]


[[!If?
   &subject=`[[!getUrlParam? &name=`id`]]`
   &operator=`EQ`
   &operand=`3`
   &then=`do something`
]]

Couldn't find a way to do it.


回答1:


Try https://modx.com/extras/package/switch extra.

[[!switch? 
   &get=`[[!getUrlParam? &name=`id`]]` 
   &c1=`1`
   &do1=`do something1`
   &c2=`2`
   &do2=`do something2`
   &c3=`3`
   &do3=`do something3`
   &default=`default value`
]]



回答2:


I could work with this solution:

 [[If?
       &subject=`[[!getUrlParam? &name=`id`]]`
       &operator=`inarray`
       &operand=`1,2,3`
       &then=`do something`
    ]]


来源:https://stackoverflow.com/questions/35101931/how-can-i-use-multiple-operands-in-an-if-condition-modx

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