Aarrgghh!!

ColdFusion 8 Mapping Application Name

I think I just discovered my favorite block of code ever. As such, this is a post so that I remember how to do this when I need to do it again, your may not be so impressed.

I was trying to figure out a terse, reusable way of making sure that my application root was mapped to my application name, and that my customtags folder be mapped as a custom tag folder. It had to work with inherited sub application.cfc's and deal with the fact that my application might not be in the root. I came up with this:

<cfset this.name = "APPNAME" />

<cfset this.mappings["/#this.name#"] = getDirectoryFromPath(getCurrentTemplatePath()) />

<cfset This.customtagpaths = "#getDirectoryFromPath(getCurrentTemplatePath())#\customtags\"/>


September 26, 2007 Posted by Terrence Ryan at 5:44 PM

ColdFusion, Web Development,



Comments

Another idea to possibly make this a bit cooler. You can even make the application name dynamic - perhaps based on a hash of the path. That way you can install N copies of the same app - at different locations - and not even need to change the app name. Just drop it in and it works.


Posted by: Raymond Camden at June 26, 2008 5:51 PM

Aarrgghh Guy! Great point, Ray. I only recently discovered that technique/pattern. You're right, it would be a great addition to this.




Posted by: Terrence Ryan at June 26, 2008 6:08 PM

Posted by Who at September 2, 2010 3:03 PM

Post a comment











Remember personal info?