176
Chapter 9: Creating and Using Custom CFML Tags
For example, the following code specifies to execute the custom tag defined by the mytag.cfm
page in the parent directory of the calling page:
<cfmodule template="../mytag.cfm">
For more information on using the
cfmodule
tag, see
CFML Reference
.
Calling custom tags using the cfimport tag
You can use the
cfimport
tag to import custom tags from a directory as a tag library. The
following example imports the tags from the directory myCustomTags:
<cfimport prefix="mytags" taglib="myCustomTags">
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 183
.
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.
name Required
if
the
template
attribute is not used. Use period-separated names to uniquely
identify a subdirectory under the CustomTags root directory.
Example:
<cfmodule name="MyApp.GetUserOptions">
identifies the file
GetUserOptions.cfm in the CustomTags\MyApp directory under the ColdFusion root
directory.
attributes The custom tag's attributes.
Attribute Description (continued)
Summary of Contents for COLDFUSION MX 61-DEVELOPING COLDFUSION MX
Page 1: ...Developing ColdFusion MX Applications...
Page 22: ...22 Contents...
Page 38: ......
Page 52: ...52 Chapter 2 Elements of CFML...
Page 162: ......
Page 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Page 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Page 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Page 266: ......
Page 314: ...314 Chapter 14 Handling Errors...
Page 344: ...344 Chapter 15 Using Persistent Data and Locking...
Page 349: ...About user security 349...
Page 357: ...Security scenarios 357...
Page 370: ...370 Chapter 16 Securing Applications...
Page 388: ...388 Chapter 17 Developing Globalized Applications...
Page 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Page 410: ......
Page 426: ...426 Chapter 19 Introduction to Databases and SQL...
Page 476: ...476 Chapter 22 Using Query of Queries...
Page 534: ...534 Chapter 24 Building a Search Interface...
Page 556: ...556 Chapter 25 Using Verity Search Expressions...
Page 558: ......
Page 582: ...582 Chapter 26 Retrieving and Formatting Data...
Page 668: ......
Page 734: ...734 Chapter 32 Using Web Services...
Page 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Page 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Page 788: ......