Jump to main content Jump to doc navigation

What is If?

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.


It can be downloaded from within the MODX Revolution manager via Package Management, or from the MODX Extras Repository, here: https://modx.com/extras/package/if

Development and Bug Reporting

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:


Available Properties

Name Description Default Value
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

Available Operators

Operator Description
!=,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)


Numeric comparison:

[[!If? &subject=`[[+total]]` &operator=`GT` &operand=`3` &then=`You have more than 3 items!`]]

String comparison:

   &then=`Hey George! Long time no see!`
   &else=`You're not George. Go away.`

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.

   &then=`This resource is not visible in the menu.`
   &else=`This resource shows up in the menu in spot [[*menuindex]].`

Example with in_array:

   &then=`This text will show if id is 3 or 4.`
   &else=`This text is printed for all other resource id's.`

Support the team building MODX with a monthly donation.

The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.


  • modmore
  • Jens Wittmann – Gestaltung & Entwicklung
  • Fabian Christen
  • Digital Penguin
  • Dannevang Digital
  • Sepia River Studios
  • Chris Fickling
  • CrewMark
  • deJaya
  • Following Sea
  • Anton Tarasov
  • eydolan
  • Raffy
  • Lefthandmedia
  • Murray Wood
  • Snow Creative
  • Nick Clark
  • Helen
  • JT Skaggs
  • krisznet
  • YJ
  • Yanni
  • Richard


$367 per month—let's make that $500!

Learn more