
178
Chapter 9: Creating and Using Custom CFML Tags
Variables created within a custom tag are deleted when the processing of the tag terminates.
Therefore, if you want to pass information back to the calling page, you must write that
information back to the Caller scope of the calling page. You cannot access the custom tag’s
variables outside the custom tag itself.
For example, use the following code in the getmd.cfm page to set the variable Doctor on the
calling page:
<cfset Caller.Doctor="Doctor " & Attributes.Name>
If the variable Doctor does not exist in the calling page, this statement creates it. If the variable
exists, the custom tag overwrites it.
The following figure shows the relationship between the variables on the calling page and the
custom tag:
One common technique used by custom tags is for the custom tag to take as input an attribute
containing the name of the variable to use to pass back results. For example, the calling page
passes returnHere as the name of the variable to use to pass back results:
<cf_mytag resultName="returnHere">
In mytag.cfm, the custom tag passes back its results using the following code:
<cfset "Caller.#Attributes.resultName#" = result>
Tip:
Be careful not to overwrite variables in the calling page from the custom tag. You should adopt a
naming convention to minimize the chance of overwriting variables. For example, prefix the returned
variable with customtagname_, where customtagname is the name of the custom tag.
Note:
Data pertaining to the HTTP request or to the current application is visible in the custom tag
page. This includes the variables in the Form, Url, Cgi, Request, Cookies, Server, Application,
Session, and Client scopes.
Using tag attributes summary
Custom tag attribute values are passed from the calling page to the custom tag page as name-value
pairs. CFML custom tags support required and optional attributes. Custom tag attributes
conform to the following CFML coding standards:
•
ColdFusion passes any attributes in the Attributes scope.
•
Use the
Attributes.
attribute_name
syntax when referring to passed attributes to
distinguish them from custom tag page local variables.
•
Attributes are case-insensitive.
•
Attributes can be listed in any order within a tag.
•
Attribute name-value pairs for a tag must be separated by a space in the tag invocation.
•
Passed values that contain spaces must be enclosed in double-quotes.
calling page
getmd.cfm
Содержание ColdFusion MX
Страница 1: ...Developing ColdFusion MX Applications...
Страница 22: ...22 Contents...
Страница 38: ......
Страница 52: ...52 Chapter 2 Elements of CFML...
Страница 162: ......
Страница 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Страница 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Страница 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Страница 266: ......
Страница 314: ...314 Chapter 14 Handling Errors...
Страница 344: ...344 Chapter 15 Using Persistent Data and Locking...
Страница 349: ...About user security 349...
Страница 357: ...Security scenarios 357...
Страница 370: ...370 Chapter 16 Securing Applications...
Страница 388: ...388 Chapter 17 Developing Globalized Applications...
Страница 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Страница 410: ......
Страница 426: ...426 Chapter 19 Introduction to Databases and SQL...
Страница 476: ...476 Chapter 22 Using Query of Queries...
Страница 534: ...534 Chapter 24 Building a Search Interface...
Страница 556: ...556 Chapter 25 Using Verity Search Expressions...
Страница 558: ......
Страница 582: ...582 Chapter 26 Retrieving and Formatting Data...
Страница 668: ......
Страница 734: ...734 Chapter 32 Using Web Services...
Страница 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Страница 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Страница 788: ......
Страница 806: ...806 Chapter 35 Sending and Receiving E Mail...