iIf

A boolean condition or value is passed into the first argument. If the condition is true the second argument is evaluated and returned, if false the third argument is evaluated and returned.

iIf(condition, expression1, expression2) → returns String

Discouraged: Use the ternary operator CF 9+ instead because it does not evaluate.
Example ternary operator: ( (condition) ? valueIfTrue : valueIfFalse )

iIf Argument Reference

condition
Required

A boolean value or an expression that evaluates to a boolean.

expression1
Required

A CFML expression that is evaluated dynamically using Evaluate if the condition is true.

expression2
Required

A CFML expression that is evaluated dynamically using Evaluate if the condition is false.

Examples sample code invoking the iIf function


Simple iIf Example

iIf( server.os.name IS "Bacon", de("Running Bacon OS"), de("Not Running Bacon OS") )

Expected Result: Not Running Bacon OS


Simple Example using Ternary Operator Instead

Instead of using iif, you should use the ternary operator CF 9+

( (server.os.name IS "Bacon") ? "Running Bacon OS" : "Not Running Bacon OS")

Expected Result: Not Running Bacon OS


Fork me on GitHub