User Guide

Table Of Contents
242 Chapter 11: Creating and Using Custom CFML Tags
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 250.
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 pages file name. The page referencing the
custom tag is referred to as the calling page.
To create and call a custom tag:
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 case-insensitive, 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
The cfusion\CustomTags directory
A subdirectory of the cfusion\CustomTags directory
A directory that you specify in the ColdFusion MX Administrator