Simple in concept, ColdFusion variables are key to building dynamic Web pages. They provide placeholders in which to put different values. ColdFusion variables are used in expressions. Expressions are generally used in two ways: inside a <cfoutput> block to build output on a Web page, and to the right of equals signs (=) in <cfset> statements. NOTE Remember the following rules when naming ColdFusion variables:
But what exactly is an expression? The ColdFusion documentation says that expressions are "language constructs that allow you to create sophisticated applications." The best way to define an expression is to say it is simply a combination of the following:
In other words, the following is an expression: #var# as is 100 Expressions can also include calculations, like this: var2-var1 Expressions may be used with CFML tags as well as in output, so this is valid: <cfset result=var2-var1> as is <cfoutput>#var2-var1#</cfoutput> TIP ColdFusion variable names can be variables themselves. If you want to assign a value to a variable, simply use <cfset> with the variable name to the left of the = and quotation marks and #s as follows: <cfset "#TheVar#"=15> |