User Guide

Table Of Contents
244 Chapter 11: Creating and Using Custom CFML Tags
Once imported, you call the custom tags using the prefix that you set when importing, as the
following example shows:
<mytags:customTagName>
where customTagName corresponds to a ColdFusion application page named
customTagName.cfm. If the tag takes attributes, you include them in the call:
<mytags:custom_tag_name attribute1=val_1 attribute2=val_2>
You can also include end tags when calling your custom tags, as the following example shows:
<mytags:custom_tag_name attribute1=val_1 attribute2=val_2>
...
</mytags:custom_tag_name>
ColdFusion calls the custom tag page twice for a tag that includes an end tag: once for the start
tag and once for the end tag. For more information on how ColdFusion handles end tags, and
how to write your custom tags to handle them, see “Handling end tags” on page 250.
One of the advantages to using the
cfimport tag is that you can define a directory structure for
your custom tags to organize them by category. For example, you can put all security tags in one
directory, and all interface tags in another. You then import the tags from each directory and give
them a different prefix:
<cfimport prefix="security" taglib="securityTags">
<cfimport prefix="ui" taglib="uiTags">
...
<security:validateUser name="Bob">
...
<ui:greeting name="Bob">
...
Reading your code becomes easier because you can identify the location of your custom tags from
the prefix.
Securing custom tags
The ColdFusion security framework enables you to selectively restrict access to individual tag files
and tag directories. This can be an important safeguard in team development. For details, see
Configuring and Administering ColdFusion MX.
Accessing existing custom tags
Before creating a custom tag in CFML, you should review the Custom Tag section of the
ColdFusion Developer Exchange at http://devex.macromedia.com/developer/gallery/index.cfm.
You might find a tag here that does what you want.
Tags are grouped in several broad categories and are downloadable as freeware, shareware, or
commercial software. You can view each tag’s syntax and usage information. The gallery
contains a wealth of background information on custom tags and an online discussion forum
for tag topics.