如何在 if 条件下使用多个操作数 (ModX)
How can I use multiple operands in an if condition (ModX)
我正在为 ModX 使用 if-extra。是否可以使用多个操作数,意味着以更短的方式编写此代码:
[[!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`
]]
找不到方法。
我可以使用这个解决方案:
[[If?
&subject=`[[!getUrlParam? &name=`id`]]`
&operator=`inarray`
&operand=`1,2,3`
&then=`do something`
]]
尝试 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`
]]
我正在为 ModX 使用 if-extra。是否可以使用多个操作数,意味着以更短的方式编写此代码:
[[!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`
]]
找不到方法。
我可以使用这个解决方案:
[[If?
&subject=`[[!getUrlParam? &name=`id`]]`
&operator=`inarray`
&operand=`1,2,3`
&then=`do something`
]]
尝试 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`
]]