Adobe COLDFUSION 9 Manual page 75

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
//The following line is valid.
var a = var b = c = d*5
//The following line is not valid.
// a = b = var c = d*5
Using number signs
Number signs (#) have a special meaning in CFML. When the ColdFusion server encounters number signs in CFML
text, such as the text in a
cfoutput
or a function.
Number signs are also called pound signs.
Is so, it replaces the text and surrounding number signs with the variable value or the result of the function. Otherwise,
ColdFusion generates an error.
For example, to output the current value of a variable named
variable name with number signs:
<cfoutput>Value is #Form.MyFormVariable#</cfoutput>
In this example, the variable
Follow these guidelines when using number signs:
• Use number signs to distinguish variables or functions from plain text.
• Surround only a single variable or function in number signs; for example, #Variables.myVar# or #Left(myString,
position)#. (However, a function in number signs can contain nested functions, such as #Left(trim(myString),
position)#.
• Do not place complex expressions, such as
such as <cfoutput>One plus one is #1 + 1#</cfoutput>, doing so mixes logic and presentation.
• Use number signs only where necessary, because unneeded number signs slow processing.
For a description of using number signs to create variable names, see
in
assignments" on page 74.
Using number signs in ColdFusion tag attribute values
You can place variables, functions, or expressions inside tag attributes by enclosing the variable or expression with
number signs. For example, if the variable CookieValue has the value "MyCookie", the following line sets the
attribute to "The value is MyCookie":
cfcookievalue
<cfcookie name="TestCookie" value="The value is #CookieValue#">
You can optionally omit quotation marks around variables used as attribute values as shown in the following example:
<cfcookie name = TestCookie value = #CookieValue#>
However, surrounding all attribute values in quotation marks is more consistent with HTML coding style.
If you use string expressions to construct an attribute value, as shown in the following example, the strings inside the
expression use single quotation marks (') to differentiate the quotation marks from the quotation marks that surround
the attribute value.
<cfcookie name="TestCookie2" value="The #CookieValue & 'ate the cookie!'#">
tag body, it checks to see if the text between the number signs is either a variable
is replaced with the value assigned to it.
Form.MyFormVariable
in number signs. Although this is allowed in a cfoutput block,
1 + 2
Last updated 8/5/2010
, you delimit (surround) the
Form.MyFormVariable
"Using number signs to construct a variable name
70

Advertisement

Table of Contents
loading

Table of Contents