Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 83

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
SetVariable function considerations
You can avoid using the
SetVariable
variable. For example, the following lines are equivalent:
<cfset SetVariable("myVar" & i, myVal)>
<cfset "myVar#i#" = myVal>
In the second line, enclosing the myVar#i# variable name in quotation marks tells ColdFusion to evaluate the name
and process any text in number signs as a variable or function. ColdFusion replaces the #i# with the value of the
variable i, so that if the value of i is 12, this code is equivalent to the line
<cfset myVar12 = myVal>
For more information on this usage, see
Using the IIF function
The
function is a shorthand for the following code:
IIf
<cfif argument1>
<cfset result = Evaluate(argument1)>
<cfelse>
<cfset result = Evaluate(argument2)>
</cfif>
The function returns the value of the result variable. It is comparable to the use of the JavaScript and Java ? : operator,
and can result in more compact code. As a result, the
expressions.
The
function requires the
IIF
example shows:
<cfoutput>
#IIf(IsDefined("LocalVar"), "LocalVar", DE("The variable is not defined."))#
</cfoutput>
If you do not enclose the string "The variable is not defined." in a
contents of the string as an expression and generates an error (in this case, an invalid parser construct error).
The
function is useful for incorporating ColdFusion logic in line in HTML code, but it entails a processing time
IIF
penalty in cases where you do not otherwise need dynamic expression evaluation.
The following example shows using
the use of the
function to prevent ColdFusion from evaluating the color strings.
DE
<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>
This code is more compact than the following example, which does not use
function by using a format such as the following to set a dynamically named
"Using number signs to construct a variable name in
function can be convenient even if you are not using dynamic
IIF
function to prevent ColdFusion from evaluating literal strings, as the following
DE
to alternate table row background color between white and gray. It also shows
IIF
Last updated 1/20/2012
assignments" on page 74.
function, the
function tries to evaluate the
DE
IIF
or
:
IIF
DE
78

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents