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:
[[!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
eg.
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
UPDATE: Please download the second, updated file shown below (forum won't allow me to remove the first)
[ed. note: okyanet last edited this post 11 years, 3 months ago.]