
Using pound signs
89
5
Executes the
UCase
function on the string argument "we all need more sleep!" to get "WE ALL
NEED MORE SLEEP!".
6
Assigns the string value "WE ALL NEED MORE SLEEP!" to the variable myStringVar.
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
cfoutput
tag body, it checks to see if the text
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
Form.MyFormVariable
, you delimit
(surround) the variable name with pound signs:
<cfoutput>Value is #Form.MyFormVariable#</cfoutput>
In this example, the variable
Form.MyFormVariable
is replaced with the value assigned to it.
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
1 + 2
in pound signs.
•
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
“Using pound signs to construct a
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
value
attribute to "The value is MyCookie":
<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!'#">
Summary of Contents for COLDFUSION MX 61-DEVELOPING COLDFUSION MX
Page 1: ...Developing ColdFusion MX Applications...
Page 22: ...22 Contents...
Page 38: ......
Page 52: ...52 Chapter 2 Elements of CFML...
Page 162: ......
Page 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Page 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Page 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Page 266: ......
Page 314: ...314 Chapter 14 Handling Errors...
Page 344: ...344 Chapter 15 Using Persistent Data and Locking...
Page 349: ...About user security 349...
Page 357: ...Security scenarios 357...
Page 370: ...370 Chapter 16 Securing Applications...
Page 388: ...388 Chapter 17 Developing Globalized Applications...
Page 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Page 410: ......
Page 426: ...426 Chapter 19 Introduction to Databases and SQL...
Page 476: ...476 Chapter 22 Using Query of Queries...
Page 534: ...534 Chapter 24 Building a Search Interface...
Page 556: ...556 Chapter 25 Using Verity Search Expressions...
Page 558: ......
Page 582: ...582 Chapter 26 Retrieving and Formatting Data...
Page 668: ......
Page 734: ...734 Chapter 32 Using Web Services...
Page 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Page 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Page 788: ......