
210
DEVELOPING
COLDFUSION 9 APPLICATIONS
Building Blocks of ColdFusion Applications
Las
t
upda
te
d 8/5/2010
•
The cfusion\CustomTags directory
•
A subdirectory of the cfusion\CustomTags directory
•
A directory that you specify in the ColdFusion Administrator
To share a custom tag among applications in multiple directories, place it in the cfusion\CustomTags directory. You
can create subdirectories to organize custom tags. ColdFusion searches recursively for the Custom Tags directory,
stepping down through any existing subdirectories until the custom tag is found.
You can have a situation where you have multiple custom tags with the same name. To guarantee which tag
ColdFusion calls, copy it to the same directory as the calling page. Or, use the
cfmodule
tag with the
template
attribute to specify the absolute path to the custom tag. For more information on
cfmodule
, see the next section.
Calling custom tags with the cfmodule tag
You can also use the
cfmessagebox
tag to call custom tags if you want to specify the location of the custom tag page.
The
cfmodule
tag is useful if you are concerned about possible name conflicts when using a custom tag, or if the
application must use a variable to dynamically call a custom tag at runtime.
Use either a
template
or
name
attribute in the tag, but you cannot use both. The following table describes the basic
cfmodule
attributes:
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
cfmessagebox
tag, see the
CFML Reference
.
Calling custom tags with 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>
Attribute
Description
template
Required if the
name
attribute is not used. Same as the
template
attribute in cfinclude. This attribute:
•
Specifies a path relative to the directory of the calling page.
•
If the path value is prefixed with "/", ColdFusion searches directories explicitly mapped in the ColdFusion
Administrator for the included file.
Example:
<cfmodule template="../MyTag.cfm">
identifies a custom tag file in the parent directory.
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.
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...