How can I use multiple operands in an if condition

2019-09-04 12:23发布

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.

2条回答
时光不老,我们不散
2楼-- · 2019-09-04 13:08

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`
]]
查看更多
小情绪 Triste *
3楼-- · 2019-09-04 13:17

I could work with this solution:

 [[If?
       &subject=`[[!getUrlParam? &name=`id`]]`
       &operator=`inarray`
       &operand=`1,2,3`
       &then=`do something`
    ]]
查看更多
登录 后发表回答