
209
DEVELOPING
COLDFUSION 9 APPLICATIONS
Building Blocks of ColdFusion Applications
Las
t
upda
te
d 8/5/2010
When ColdFusion processes the page containing this tag, it could output the message:
December 5, 1987 is Ted Cantor's Birthday.
Please wish him well.
A custom tag can also have a body and end tag, for example:
<cf_happybirthdayMessge name="Ellen Smith" birthDate="June 8, 1993">
<p> Happy Birthday Ellen!</p>
<p> May you have many more!</p>
</cf_happybirthdayMessge>
This tag could output the message:
June 8, 1993 is Ellen Smith's Birthday.
Happy Birthday Ellen!
May you have many more!
For more information about using end tags, see “
Handling end tags
” on page 217.
Creating and calling custom tags
You implement a custom tag with a single ColdFusion page. You then call the custom tag from a ColdFusion page by
inserting the prefix
cf_
before the page’s filename. The page that references the custom tag is referred to as the
calling
page.
1
Create a ColdFusion page, the custom tag page, that shows the current date:
<cfoutput>#DateFormat(Now())#</cfoutput>
2
Save the file as date.cfm.
3
Create a ColdFusion page, the calling page, with the following content:
<html>
<head>
<title>Date Custom Tag</title>
</head>
<body>
<!--- Call the custom tag defined in date.cfm --->
<cf_date>
</body>
</html>
4
Save the file as callingdate.cfm.
5
View callingdate.cfm in your browser.
This custom tag returns the current date in the format DD-MMM-YY.
As you can see from this example, creating a custom tag in CFML is no different from writing any ColdFusion page.
You can use all CFML constructs, as well as HTML. You are free to use any naming convention that fits your
development practice. Unique descriptive names make it easy for you and others to find the right tag.
Note:
Although tag names in ColdFusion pages are not case sensitive, custom tag filenames must be lowercase on UNIX.
Storing custom tag pages
You must store custom tag pages in any one of the following:
•
The same directory as the calling page