User Guide

Table Of Contents
Passing data to custom tags 245
Tag names with the cf_ preface are CFML custom tags; those with the cfx_ preface are
ColdFusion extensions written in C++. For more information about the CFX tags, see
Chapter 12, “Building Custom CFXAPI Tags,” on page 259.
If you do not find a tag that meets your specific needs, you can create your own custom tags in
CFML.
Passing data to custom tags
To make your custom tags flexible, you will often want to pass data to them for processing. This
section describes how to write custom tags that take tag attributes and other data as input from a
calling page.
Passing values to and from custom tags
Because custom tags are individual ColdFusion pages, variables and other data are not
automatically shared between a custom tag and the calling page. To pass data from the calling
page to the custom tag, you can specify attribute name/value pairs in the custom tag, just as you
do for normal HTML and CFML tags.
For example, to pass the value of the NameYouEntered variable to the cf_getmd tag, you can call
the custom tag as follows:
<cf_getmd Name=#NameYouEntered#>
To pass multiple attributes to a custom tag, separate them with a space in the tag as follows:
<cf_mytag Firstname="Thadeus" Lastname="Jones">
In the custom tag, you use the Attributes scope to access attributes passed to the tag. Therefore, in
the getmd.cfm page, you refer to the passed attribute as
Attributes.Name. The mytag.cfm
custom tag page refers to the passed attributes as
Attributes.Firstname and
Attributes.Lastname.
The custom tag page can also access variables set in the calling page by prefixing the calling page’s
local variable with Caller. However, this is not the best way to pass information to a custom tag,
because each calling page would be required to create variables with the names required by the
custom tag. You can create more flexible custom tags by passing parameters using attributes.
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.