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.
- The same directory as the calling page
- The cfusion\CustomTags directory
- A subdirectory of the cfusion\CustomTags directory
- 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.
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.
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.
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.
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.