Using Pound Signs; Using Pound Signs In Coldfusion Tag Attribute Values - MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual

Developing coldfusion mx applications
Table of Contents

Advertisement

Executes the
5
UCase
NEED MORE SLEEP!".
Assigns the string value "WE ALL NEED MORE SLEEP!" to the variable myStringVar.
6
ColdFusion completes steps 1-3 before invoking the function.

Using pound signs

Pound signs (#) have a special meaning in CFML. When the ColdFusion server encounters
pound signs in CFML text, such as the text in a
between the pound signs is either a variable or a function.
Is so, it replaces the text and surrounding pound 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
(surround) the variable name with pound signs:
<cfoutput>Value is #Form.MyFormVariable#</cfoutput>
In this example, the variable
Follow these guidelines when using pound signs:
Use pound signs to distinguish variables or functions from plain text.
Surround only a single variable or function in pound signs; for example, #Variables.myVar# or
#Left(myString, position)#. (However, a function in pound signs can contain nested functions,
such as #Left(trim(myString), position)#.
Do not put complex expressions, such as
Use pound signs only where necessary, because unneeded pound signs slow processing.
The following sections provide more details on how to use pound signs in CFML. For a
description of using pound signs to create variable names, see
variable name in assignments" on page 93

Using pound signs in ColdFusion tag attribute values

You can put variables, functions, or expressions inside tag attributes by enclosing the variable or
expression with pound signs. For example, if the variable CookieValue has the value "MyCookie",
the following line sets the
<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!'#">
function on the string argument "we all need more sleep!" to get "WE ALL
Form.MyFormVariable
attribute to "The value is MyCookie":
cfcookie
value
tag body, it checks to see if the text
cfoutput
Form.MyFormVariable
is replaced with the value assigned to it.
in pound signs.
1 + 2
"Using pound signs to construct a
, you delimit
Using pound signs
89

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the COLDFUSION MX 61-DEVELOPING COLDFUSION MX and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

This manual is also suitable for:

Coldfusion mx

Table of Contents