Lucas Reply #1, 1 year, 1 month ago
AndIf - for MODx Revolution
AndIf is an 'If...then...else' snippet that accepts multiple AND/OR conditions.
It's based on the existing 'If' snippet by splittingred and OpenGeek.
I'm still testing and am hoping for some constructive feedback here
Cheers,
Luke
The Snippet
Snippet code is attached to this post. Call it like this:
Property Descriptions
&condition=``
Note: For in_array operator, ensure array is input as a comma ',' delimited string
&operator=`` Global operator to be applied to all conditions provided.
AndIf is an 'If...then...else' snippet that accepts multiple AND/OR conditions.
It's based on the existing 'If' snippet by splittingred and OpenGeek.
I'm still testing and am hoping for some constructive feedback here
Cheers,
Luke
The Snippet
Snippet code is attached to this post. Call it like this:
[[!AndIf? &condition=`` <-- condition(s) to test (see description below) &operator=`` <-- AND or OR (defaults to AND) &then=`` <-- result if conditions met (defaults to 'true') &else=`` <-- result if not (defaults to 'false') ]]
Property Descriptions
&condition=``
- Each condition is of the format subject operator operand, separated with one space ' '
eg. &condition=`5 < 6` (returns true) - Separate multiple conditions with a pipe '|'
- Tested up to 10 conditions, worked fine

- Makes use of all conditional operators supported by If
Single condition: &condition=`[[*parent]] isnot 2` Multiple conditions: &condition=`[[*template]] eq 5|[[*image]] isempty 1`
Note: For in_array operator, ensure array is input as a comma ',' delimited string
- eg. &condition=`5 in_array 4,5,6` (returns true)
&operator=`` Global operator to be applied to all conditions provided.
- Accepts 'AND' or 'OR' (defaults to 'AND')
- eg. IF condition1 AND condition2 ARE BOTH TRUE, OUTPUT TRUE
IF EITHER condition1 OR condition2 ARE TRUE, OUTPUT TRUE