User Guide

Table Of Contents
246 Chapter 11: Creating and Using Custom CFML Tags
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-quotation marks.
Use the cfparam tag with a default attribute at the top of a custom tag to test for and assign
defaults for optional attributes that are passed from a calling page. For example:
<!--- The value of the variable Attributes.Name comes from the calling page.
If
the calling page does not set it, make it “Who
". --->
<cfparam name="Attributes.Name" default="Who">
calling page
getmd.cfm