如何在if条件下使用多个操作数(ModX)

时间:2016-01-30 12:44:27

标签: if-statement modx modx-revolution

我正在为ModX使用if-extra。是否可以使用mutliple操作数,这意味着以更短的方式编写此代码:

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

无法找到办法。

2 个答案:

答案 0 :(得分:3)

尝试额外https://modx.com/extras/package/switch

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

答案 1 :(得分:2)

我可以使用这个解决方案:

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