<!--- Create a variable called Doctor, make its value "Doctor "
followed by the value of the variable Attributes.Name.
Make its scope Caller so it is passed back to the calling page
--->
<cfset Caller.Doctor="Doctor " & Attributes.Name>
Save the page as
4
Open the file
5
The calling page uses the
Reviewing the code
The following table describes the code and its function:
Code
<cfset NameYouEntered="Smith">
<cfoutput>
Before you leave this page, you're
#Variables.NameYouEntered#.<br>
</cfoutput>
<cf_getmd Name="#NameYouEntered#">
<cfparam name="Attributes.Name"
default="Who">
<cfset Caller.Doctor="Doctor " &
Attributes.Name>
<cfoutput>
You are now
#Variables.Doctor#.<br>
</cfoutput>
Passing custom tag attributes using CFML structures
You can use the reserved attribute
a structure. The
attribute names as the keys and the attribute values as the values. You can freely mix
attributecollection
The key-value pairs in the structure specified by the
into the custom tag page's Attributes scope. This has the same effect as specifying the
attributecollection
tag page refers to the attributes passed using
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.
180
Chapter 9: Creating and Using Custom CFML Tags
.
getmd.cfm
in your browser.
callingpage.cfm
custom tag and displays the results.
getmd
attributecollection
attributecollection
with other attributes when you call a custom tag.
entries as individual attributes when you call the custom tag. The custom
Description
In the calling page, create a variable NameYouEntered and
assign it the value "Smith."
In the calling page, display the value of the
NameYouEntered variable before calling the custom tag.
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.
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.
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 Atributes.Name variable.
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.)
to pass attributes to custom tags using
attribute must reference a structure containing the
attributecollection
attributecollection
attribute get copied
the same way as it does other
Need help?
Do you have a question about the COLDFUSION MX 61-DEVELOPING COLDFUSION MX and is the answer not in the manual?
Questions and answers