COLDFUSION CUSTOM TAGS

www.

How do I use Custom Tags with ColdFusion?

The follow article explains how to use ColdFusion custom tags. A custom tag is a series of ColdFusion tags combined into one tag and called in a similar manner to normal ColdFusion tags. For example, you can create a page called script.cfm and then within your code can call this as cf_script.

There are three different methods for creating and accessing your custom tag:

  1. Place your custom tag(s) within a directory in your site and use the cfmodule tag to call the custom tag as you need it (see below for more details). This is the method we recommend as it gives you full control over your custom tag(s) and requires you to have only a single copy of your tag.
  2. Store the custom tag file in the same folder as the .cfm page that is calling the custom tag. If you are calling the custom tag from multiple folders in your website you will need to have a copy of the custom tag file in each folder.
  3. Upload the custom tag file to your website’s folder and contact us with the file name. We will move it to the custom tags folder for you. Please try to use a unique name. This method is not generally recommended as it gives you the least amount of control over changing your custom tags.

Note: If you would like us to place the custom tag file in the server’s custom tag folder you will need to use a unique name for the file, preferably one that contains part of your domain name. Creating a unique name prevents other customers from creating tags with a similar name.

Using the cfmodule tag

The cfmodule tag allows you to call the file directly, rather than calling your custom tag as cf_tagname. This method allows you to place all of your custom tags in one folder and then access them from anywhere within your website. Once your folder is created you will need to create a mapping for this directory using the instructions found here. Once the mapping is configured you can begin using your custom tags.

For example, if you have a custom tag located in customtags folder called mytag.cfm that has two parameters (X and Y), we would first create a mapping called custtags that points to the customtags folder in your website. You would then call the tag in your code as follows:

<cfmodule template="/custtags/mytag.cfm" X="3" Y="2">

Attribute Req/Opt Description
template Required unless name attribute is used Mutually exclusive with the name attribute. A path to the page that implements the tag.
* Relative path: expanded from the current page
* Absolute path: expanded using ColdFusion mapping
A physical path is not valid.
attribute_name Optional Attribute for a custom tag. You can include multiple instances of this attribute to specify the parameters of a custom tag.

For example, if you have a custom tag located in root websites folder called mytag-domainname.cfm that has two parameters (X and Y), you would call the tag in your code as follows:
<cfmodule Template="mytag-domainname.cfm" X="3" Y="2">

The above information was taken from http://livedocs.macromedia.com

For further information on cfmodule for ColdFusion 5.0 you can view Macromedia’s livedocs website here.

For further information on cfmodule for ColdFusion MX 6.1 you can view Macromedia’s livedocs website here.

For further information on cfmodule for ColdFusion MX 7.0 you can view Macromedia’s livedocs website here.

Comments are closed.

By using this website you consent to the use of cookies in accordance with our Privacy Notice. You may opt-out at any time in the Cookies section of the Privacy Notice page.