
213
DEVELOPING
COLDFUSION 9 APPLICATIONS
Building Blocks of ColdFusion Applications
Las
t
upda
te
d 8/5/2010
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 not case sensitive.
•
Attributes can be listed in any order within a tag.
•
in the tag invocation, a space must separate attribute name-value pairs.
•
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">
•
Use the
cfparam
tag or a
cfif
tag with an
IsDefined
function at the top of a custom tag to test for required
attributes that must be passed from a calling page; for example, the following code issues an abort if the user does
not specify the Name attribute to the custom tag:
<cfif not IsDefined("Attributes.Name")>
<cfabort showError="The Name attribute is required.">
</cfif>
Custom tag example with attributes
The following example creates a custom tag that uses an attribute that is passed to it to set the value of a variable called
Doctor on the calling page.
1
Create a ColdFusion page (the calling page) with the following content: