User Guide

Table Of Contents
248 Chapter 11: Creating and Using Custom CFML Tags
4.
Save the page as getmd.cfm.
5.
Open the file callingpage.cfm in your browser.
The calling page uses the
getmd custom tag and displays the results.
Reviewing the code
The following table describes the code and its function:
Passing custom tag attributes using CFML structures
You can use the reserved attribute
attributecollection to pass attributes to custom tags using
a structure. The
attributecollection attribute must reference a structure containing the
attribute names as the keys and the attribute values as the values. You can freely mix
attributecollection with other attributes when you call a custom tag.
The key-value pairs in the structure specified by the
attributecollection attribute get copied
into the custom tag pages Attributes scope. This has the same effect as specifying the
attributecollection entries as individual attributes when you call the custom tag. The custom
tag page refers to the attributes passed using
attributecollection the same way as it does other
attributes; for example, as Attributes.CustomerName or Attributes.Department_number.
Note: You can use both tag attributes and attributecollections. If you pass an attribute with the
same name using both methods, ColdFusion passes only the tag attribute to the custom tag and
ignores the corresponding attribute from the attribute collection.
Code Description
<cfset NameYouEntered="Smith">
In the calling page, create a variable NameYouEntered and
assign it the value "Smith."
<cfoutput>
Before you leave this page, you're
#Variables.NameYouEntered#.<br>
</cfoutput>
In the calling page, display the value of the
NameYouEntered variable before calling the custom tag.
<cf_getmd Name="#NameYouEntered#">
In the calling page, call the getmd custom tag and pass it the
Name attribute whose value is the value of the local variable
NameYouEntered.
<cfparam name="Attributes.Name"
default="Who">
The custom tag page normally gets the Name variable in the
Attributes scope from the calling page. Assign it the value
"Who" if the calling page did not pass an attribute.
<cfset Caller.Doctor="Doctor " &
Attributes.Name>
In the custom tag page, create a variable called Doctor in the
Caller scope so it will exist in the calling page as a local
variable.
Set its value to the concatenation of the string "Doctor" and
the value of the Attributes.Name variable.
<cfoutput>
You are now
#Variables.Doctor#.<br>
</cfoutput>
In the calling page, display the value of the Doctor variable
returned by the custom tag page. (This example uses the
Variables scope prefix to emphasize the fact that the
variable is returned as a local variable.)