User Guide

174 Chapter 10 Reusing Code
Using existing custom tags
Before creating a custom tag in CFML, you should review the Custom Tag section of
the ColdFusion Developer Exchange. Tags are grouped in several broad categories
and are downloadable as freeware, shareware, or commercial software. You can
quickly view each tags syntax and usage information. The Gallery contains a wealth
of background information on custom tags and an online discussion forum for tag
topics.
Tag names with the
cf_ preface are CFML custom tags; those with the cfx_ preface
are ColdFusion Extensions written in C++. For more information about the CFX tags,
see Chapter 21, Building Custom CFXAPI Tags on page389.
If you do not find a tag that meets your specific needs, you can create your own
custom tags in CFML.
Creating custom CFML tags
Creating a custom tag in CFML is no different from writing any CFML 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
While tag names in ColdFusion pages are case-insensitive, custom tag filenames
must be lowercase on UNIX.
Variable scopes and special variables
ColdFusion provides several variable scope types and built-in variables that help you
pass information between calling pages and custom tag pages.
Use the Attributes scope in the custom tag page to refer to the attributes passed
by the calling page. For example, assume the calling page has the following line:
cf_mytag Firstname="Thadeus" Lastname="Jones">
In this case, the mytag.cfm custom tag page refers to the passed attributes as
Attributes.Firstname and Attributes.Lastname.
Use the Caller scope in the custom tag page to refer to local variables in the
calling tag page. You use the Caller scope to return values to the calling page, but
you can also use this scope to access any local variables on the calling page.
Use the Request scope for variables in nested tags. The Request scope is available
to the base page, all pages it includes, all custom tag pages it calls, and all custom
tag pages called by the included pages and custom tag pages. Collaborating
custom tags that are not nested in a single tag can exchange data via the request
structure. The Request scope is represented as a structure named
Request.