How can I use multiple operands in an if condition

2019-09-04 12:40发布

问题:

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`
    ]]