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 CF9+ instead because it does not evaluate. Example ternary operator: ( (condition) ? valueIfTrue : valueIfFalse )

Argument Reference

condition boolean
Required

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

expression1 string
Required

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

expression2 string
Required

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

Links more information about iIf

Examples
Sample code invoking the iIf function

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

Expected Result: Not Running Bacon OS

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

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub