Other Ways of Calling Custom Tags
One problem with calling custom tags using the cf_ syntax we have seen thus far is that there no way to deal with name conflicts. ColdFusion simply uses the first file it finds that matches the tag name specified. For example, if you had a file in the current directory called "FetchRecord.cfm" and a custom tag file in the cfusion/CustomTags directory with the same name. You cannot access the custom tag file in the cfusion/CustomTags directory using the cf_FetchRecord syntax. ColdFusion provides two ways to deal with the naming conflict.
The <cfmodule> tag allows you to point directly to the custom tag you want to call. It takes the following syntax:
The custom tag's attributes are passed to the custom tag in the same way as they are using the cf_ syntax. The example below illustrates the use of <cfmodule> to call a custom tag.
The example above shows how the attributes can be passed in to the custom tags in separate name-value pairs. It is also possible to pass in the attributes as a single structure using <cfmodule>'s attributecollection attribute:
Custom tags with close tags can also be called with <cfmodule> as shown in the example below.
Finally, with <cfmodule>, custom tags can be specified using dot notation. In this case, the name attribute replaces the template attribute. This is shown in the sample below:
The <cfimport> tag is used to import a group of custom tags that can be referenced with a given prefix. The syntax is shown below:
<cfimport prefix="prefix" taglib="path_to_tag_directory">
The prefix attribute is used to specifiy a tag qualifier. A custom tag called "bar" in a library qualified with the "foo" prefix would be called as follows:
The taglib attribute points to the directory holding the custom tags. The directory path can be relative to:
- the current page location
- the web root (the page should start with a "/")
- a directory specified in the Administrator ColdFusion mappings page (the page should start with a "/")