User Guide

Table Of Contents
241
CHAPTER 11
Creating and Using Custom CFML Tags
This chapter describes how to create and use custom CFML tags that encapsulate common code.
Contents
Creating custom tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
Passing data to custom tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
Managing custom tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
Executing custom tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
Nesting custom tags. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
Creating custom tags
Custom tags let you extend CFML by adding your own tags to the ones supplied with
ColdFusion. After you define a custom tag, you can use it on a ColdFusion page just as you
would any of the standard CFML tags, such as
cfquery and cfoutput.
You use custom tags to encapsulate your application logic so that it can be referenced from any
ColdFusion page. Custom tags allow for rapid application development and code reuse while
offering off-the-shelf solutions for many programming chores.
For example, you might create a custom tag, named
cf_happybirthday, to generate a birthday
message. You could then use that tag in a ColdFusion page, as follows:
<cf_happybirthday name="Ted Cantor" birthDate="December 5, 1987">
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>