User Guide
76 Developing Web Applications with ColdFusion
7. Open the file callingpage.cfm in your browser.
The calling page uses the
getmd custom tag and displays the results.
Code Review
Tip Be careful not to overwrite variables that might already exist on the
calling page. You should adopt a naming convention to minimize the
chance of overwriting variables. For example, prefix the returned variable
with customtagname_, with customtagname being the name of the
custom tag.
Note Data pertaining to the HTTP request or to the current application is
visible. This includes the variables in FORM, URL, CGI, COOKIES,
SERVER, APPLICATION, SESSION, and CLIENT scopes.
The Request scope is a reserved variable/scope that allows you to store data pertaining
to the complete hierarchy of custom tags used in a single page request. It is a structure
named "request." The variable is available to all templates: base, includes, and custom
tags. Collaborating custom tags that are not nested in a single tag can exchange data
via the request structure. You should assign a unique name for each variable. You
should store data in structures nested inside the request scope.
Code Description
<CFSET NameYouEntered="Smith">
In the calling page, create a variable
NameYouEntered and assign it the value
"Smith."
<CF_GETMD NAME="#NameYouEntered#">
In the calling page, call the getMD
custom tag and pass it the NAME
parameter whose value is the value of
the variable NameYou Entered.
<CFPARAM VALUE="Attributes.Name"
DEFAULT="Who"
Assign the value "Who" to Name if it has
no value.
<CFSET CALLER.DOCTOR="Doctor " &
"#ATTRIBUTES.NAME#">
See below. (It is helpful to look at this
code from right to left.)
#ATTRIBUTES.NAME#
Get the value of the variable NAME from
the calling page
<CFSET DOCTOR="Doctor " &
"#ATTRIBUTES.NAME#">
Create a variable called DOCTOR, make
its value "Doctor NAME"
<CFSET CALLER.DOCTOR="Doctor " &
"#ATTRIBUTES.NAME#">
Make the variable’s scope CALLER so
that you can pass it back to the calling
page