Author: Steven Neiland
Published:

Warning: This blog entry was written two or more years ago. Therefore, it may contain broken links, out-dated or misleading content, or information that is just plain wrong. Please read on with caution.

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.
<cfcomponent>
      <!--- Specify a folder containing custom tags to be used by this application --->
      <cfset this.customtagpaths
            = "c:\[directory path of our application code]\[customtag folder name]">

</cfcomponent>

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.

<cfcomponent>
      <!--- Specify a folder containing custom tags to be used by this application --->
      <cfset this.customtagpaths
            = ListAppend(THIS.customtagpaths,"c:\[directory path of our application code]\[customtag folder name 1]">

      <cfset this.customtagpaths
            = ListAppend(THIS.customtagpaths,"c:\[directory path of our application code]\[customtag folder name 2]">

</cfcomponent>

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.

<cfcomponent>
      <!--- Specify a folder containing custom tags to be used by this application --->
      <cfset this.customtagpaths
            = getDirectoryFromPath(getCurrentTemplatePath()) & "customtags">

</cfcomponent>

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.

What Do You Think?

Reader Comments

Post a Comment

Comment Etiquette:

  • Please keep comments on-topic.
  • Please do not post unrelated questions or large chunks of code.
  • Please do not engage in flaming/abusive behaviour.
  • Comments that contain or appear to be advertisments, will not be published.
  • Comments that appear to be created for the purpose of linkbuilding to commercial sites will be removed.

We are all adults here so play nice.

*
*



Archives Blog Listing

Tag Listing

Learn CF In A Week

Treehouse

 
Fork me on GitHub