A logical conditional snippet that allows for conditionals in MODx.
If was written by Jason Coward (opengeek) and Shaun McCormick (splittingred) and first released on Oct 29th, 2009.
If is stored and developed in GitHub, and can be found here:http://github.com/splittingred/If
Bugs can be filed here: http://github.com/splittingred/If/issues
The If snippet can be called using the tags:
or, in case your subject can be modified before the resource cache get cleared use the uncached syntax:
|subject||The value to perform the conditional on.|
|operator||The operator to compare the subject against.||=|
|operand||If needed, the value to compare the subject against using the operator.|
|then||If the condition is true, output this.|
|else||If the condition is false, output this.|
|debug||If true, print out all the passed properties.||0|
|die||If debug and this is true, die() after printing the properties.||0|
|!=,neq,not,isnot,isnt,unequal,notequal||Passes if the subject is unequal to the operand.|
|==,=,eq,is,equal,equals,equalto||Passes if the subject is equal to the operand.|
|<,lt,less,lessthan||Passes if the subject is less than the operand.|
|>,gt,greater,greaterthan||Passes if the subject is greater than the operand.|
|<=,lte,lessthanequals,lessthanorequalto||Passes if the subject is less than or equal to the operand.|
|>=,gte,greaterthanequals,greaterthanequalto||Passes if the subject is greater than or equal to the operand.|
|isempty,empty||Passes if the subject is empty.|
|!empty,notempty,isnotempty||Passes if the subject is not empty.|
|isnull,null||Passes if the subject is null.|
|inarray,in_array,ia|| Passes if the subject is found in the operand list. (comma-delimited string)
Inline snippet calls:
When using the If snippet for checking a resource field or template variable (or other value that doesn't change before the cache does), be sure to use the cached snippet call to check the condition to make sure it doesn't need to process on every request.
As requested an example with inarray.