Postpones evaluation of a string as an expression, when it is passed as a parameter to the IIf or Evaluate functions. Escapes any double quotation marks in the parameter and wraps the result in double quotation marks.
This function is especially useful with the IIf
function, to prevent the function from evaluating a string that is to be output.
This applies to expressions that are not surrounded by pound signs. (If pound signs surround any part of an expression, a ColdFusion function evaluates that part first, regardless of whether the DE
function is present.)
Parameter, surrounded by double quotation marks, with any inner double quotation marks escaped.
DE(string)
Parameter | Description |
---|---|
string |
String to evaluate, after delay |
<condition> <true expression> <false expression> iif( 1 eq 2, DE('#Var1#'), DE('#Var2#'))
ColdFusion evaluates whatever is surrounded by pounds in the expression before executing it. So, although this expression is never true (because Var1
does not exist), the expression fails with an 'Error Resolving Parameter' error, because ColdFusion evaluates #Var1#' and #Var2#' before executing either expression.
iif( 1 eq 2, DE('Var1'), DE('Var2'))
The following example uses IIF
to alternate table-row background colors, white and gray. It uses the DE
function to prevent ColdFusion from evaluating the color strings.
<cfoutput>
<table border="1" cellpadding="3"> <cfloop index="i" from="1" to="10"> <tr bgcolor="#IIF( i mod 2 eq 0, DE("white"), DE("gray") )#"> <td> hello #i# </td> </tr> </cfloop> </table> </cfoutput>
For more information and code examples, see Developing ColdFusion MX Applications with CFML.
<!--- This example shows the use of DE and Evaluate ---> <h3>DE Example</h3> <cfif IsDefined("FORM.myExpression")> <h3>The Expression Result</h3> <cftry> <!--- Evaluate the expression ---> <cfset myExpression = Evaluate(FORM.myExpression)> <!--- Use DE to output the value of the variable, unevaluated ---> <cfoutput> <I>The value of the expression #Evaluate(DE(FORM.MyExpression))# is #MyExpression#.</I> </cfoutput> <!--- specify the type of error for which we are searching ---> <cfcatch type = "Any"> <!--- the message to display ---> <h3>Sorry, there's been an <B>Error</B>. Try a simple expression, such as "2+2".</h3> <cfoutput> <!--- and the diagnostic message from ColdFusion Server ---> <p>#cfcatch.message# </cfoutput> </cfcatch> </cftry> </cfif>