Per Application Custom Tag Directories

Published: {ts '2013-03-05 00:00:00'}
Author: Steven Neiland
Site Url: http://www.neiland.net/article/per-application-custom-tag-directories/

I don't use custom tags very often, but like every tool they do have uses. According to the ColdFusion Livedocs Custom Tags Page when you create a custom tag it can be placed in one of a few different places.

  1. The same directory as the calling page
  2. The cfusion\CustomTags directory
  3. A subdirectory of the cfusion\CustomTags directory
  4. A directory that you specify in the ColdFusion Administrator

Or you can use the <cfmodule> or <cfimport> tags to load the tags from a alternative location from within your application code.

Specify Per Application

While that is all well and good, since ColdFusion 8 we have also had the ability to specify a direct path to a custom tag folder specific to our application. This is useful when you do not have access to the ColdFusion administrator.

To do this we just set the "this.customtagpaths" variable in Application.cfc.

Note: It is important to note two things.

  1. The path specified is a system directory path not a web address.
  2. This function can be disabled in the ColdFusion administrator.

Multiple Custom Tag Folders

Additionally the variable name hints that we can specify more than one custom tag folder path. To do this if you have multiple custom tag folders you can append them as a list to the variable.

Unknown Install Directory

Of course sometimes we do not know where our application is going to be installed. This is especially true of open source applications. While it is possible for the person installing the application to modify the "this.customtagpaths" variable, this is a less than ideal.

Fortunately there is a simple solution. Assuming for this example that we are placing our custom tags folder in our application root and we are simply naming it "customtags", here is how we can dynamically determine the directory path on the server.

In Conclusion

Yes custom tags are old school these days, but they still have their uses and hopefully this little tip will help them be more accessible for future developers.