Custom Tag Example - MACROMEDIA COLDFUSION 5-DEVELOPING Develop Manual

Table of Contents

Advertisement

178

Custom tag example

In this example, we create 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.
To create a custom tag:
1
2
3
4
5
6
7
The calling page uses the
Create a new application page (the calling page) in ColdFusion Studio.
Modify the file so that it appears as follows:
<html>
<head>
<title>Enter Name</title>
</head>
<body>
<!--- Enter a name, which could also be done in a form --->
<!--- This example simply uses a cfset --->
<cfset NameYouEntered="Smith">
<!--- Display the current name --->
<cfoutput>
Before you leave this page, you're #NameYouEntered#.<br>
</cfoutput>
<!--- go to the custom tag --->
<CF_GetMD Name="#NameYouEntered#">
<!--- Come back from the Custom tag --->
<!--- display the results of the custom tag --->
<cfoutput>
You are now #Variables.Doctor#.<br>
</cfoutput>
</body>
</html>
Save the page as
callingpage.cfm
Create another new page (the custom tag) in ColdFusion Studio.
Enter the following code:
<!--- 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">
<!--- 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
getmd.cfm
Open the file
callingpage.cfm
.
.
in your browser.
custom tag and displays the results.
getmd
Chapter 10 Reusing Code

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 5

Table of Contents