User Guide

IIf 517
IIf
Description
Evaluates a Boolean conditional dynamic expression. Depending on whether the expression is
true or false, dynamically evaluates one of two string expressions and returns the result. This
function is convenient for incorporating a
cfif tag in-line in HTML.
For general conditional processing, see
cfif. For error handling, see cftry. For more
information, see Developing ColdFusion MX Applications.
Returns
If result is True, returns the value of Evaluate(string_expression1); otherwise, returns the
value of
Evaluate(string_expression2).
Category
Decision functions, Dynamic evaluation functions
Function syntax
IIf(condition, string_expression1, string_expression2)
See also
DE, Evaluate
Parameters
Usage
The IIf function is a shortcut for the following construct:
<cfif condition>
<cfset result = Evaluate(string_expression1)>
<cfelse>
<cfset result = Evaluate(string_expression2)>
</cfif>
The expressions string_expression1 and string_expression2 must be string expressions, so that they
are not evaluated immediately as the parameters of
IIf. For example:
IIf(y is 0, DE("Error"), x/y)
If y = 0, this generates an error, because the third expression is the value of x/0 (invalid
expression).
ColdFusion evaluates string_expression1 and string_expression2. To return the string itself, use the
DE function.
Parameter Description
condition An expression that can be evaluated as a Boolean.
string_expression1 A string or a variable that contains one. Expression to evaluate and return if
condition is True.
string_expression2 A string or a variable that contains one. Expression to evaluate and return if
condition is False.