
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)
Содержание COLDFUSION MX 61-DEVELOPING COLDFUSION MX
Страница 1: ...Developing ColdFusion MX Applications...
Страница 22: ...22 Contents...
Страница 38: ......
Страница 52: ...52 Chapter 2 Elements of CFML...
Страница 162: ......
Страница 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Страница 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Страница 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Страница 266: ......
Страница 314: ...314 Chapter 14 Handling Errors...
Страница 344: ...344 Chapter 15 Using Persistent Data and Locking...
Страница 349: ...About user security 349...
Страница 357: ...Security scenarios 357...
Страница 370: ...370 Chapter 16 Securing Applications...
Страница 388: ...388 Chapter 17 Developing Globalized Applications...
Страница 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Страница 410: ......
Страница 426: ...426 Chapter 19 Introduction to Databases and SQL...
Страница 476: ...476 Chapter 22 Using Query of Queries...
Страница 534: ...534 Chapter 24 Building a Search Interface...
Страница 556: ...556 Chapter 25 Using Verity Search Expressions...
Страница 558: ......
Страница 582: ...582 Chapter 26 Retrieving and Formatting Data...
Страница 668: ......
Страница 734: ...734 Chapter 32 Using Web Services...
Страница 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Страница 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Страница 788: ......
Страница 806: ...806 Chapter 35 Sending and Receiving E Mail...