THIS.mappings
I’ve always been a bit perturbed at the CFIMPORT tag, both because you have to use the tag on every page in which you’ll call the prefixed custom tag, including pages that are called with CFINCLUDE (will save that rant for another time), and also because the taglib attribute cannot take a variable. To illustrate, you cannot do this:
<!--- this does not work ---> <cfset request.tagpath = "/var/www/tagsdirectory/" /> <cfimport prefix="t" taglib="#request.tagpath#" />
As you probably know, you must declare the custom tag path in the cfadmin, then call the CFIMPORT tag using the name you assigned to the path in the admin. Like so:
<cfimport prefix="t" taglib="/tagpath" />
That is until now. In ColdFusion 8 aka Scorpio aka SomeOtherCoolName, you can now create application-specific paths for your custom tags. You do so by creating a structure called THIS.mappings in your Application.cfc, then adding keys and values to this structure referencing the tag path name and the tag path directory, respectively. Like so:
<cfcomponent displayname="Application"> <!--- application-specific custom tag paths ---> <cfset this.mappings = structnew() /> <cfset this.mappings["/tagpath"] = "/var/www/tagsdirectory/" />
Note the required forward slash preceeding the tag name you assign. Now just call the CFIMPORT tag like normal at the top of your page:
<cfimport prefix="t" taglib="/tagpath" />
Bada bing bada boom, dynamic tag paths. HTH.











October 24th, 2008 at 6:17 pm
Well written article.