Raymond Camden's Blog Rss

Ask a Jedi: Controlling where ColdFusion looks to run a custom tag

3

Posted in ColdFusion | Posted on 04-23-2007 | 1,440 views

Eric asks this question regarding custom tags and a move from ColdFusion 5 to MX:

Our Application is still running with CF5 but since we have much more traffic on the site we also many problems that coldfusion crashes cause of memory leaks. To solve these problems we decided to upgrade to CFMX7. During tests i found out that doesn't work in the same way as in CF5. We have the following structure in the CustomTags directory:

CustomTags
at = country subdir austria
de = language subdir german
ch = country subdir switzerland
de = language subdir german
en = language subdir english

normally every customtag is in the root directory but if there are special needs there can be also a version (same name) in one of the upper shown directory structure. when i called a custom tag in CF5 the one from the root directory was called but in CFMX7 the one in a subdirectory will be used (if there's a copy of BlahBlah). Is there a way to fix these behavoir that CFMX7 uses customstags from subdir first?

The name attribute of cfmodule is a syntax that I do not normally use. In a way, it is a bit closer to cf_ syntax in that you don't specify a full name, but just the name of the tag. The syntax does let you specify subdirectories though. You should have been able to do something like this in your code:

view plain print about
1<cfmodule name="en.login">

Or - if the language was determined at runtime:

view plain print about
1<cfmodule name="#session.language#.login">

But it sounds like you had a login (and I"m just using that name as an example) in your root custom tag folder as well. I just ran a test on my machine with a "hello.cfm" in the root of custom tags and one in a subfolder. Using cfmodule name="hello" resulted in the root tag being run, which seems right to me.

So what do I propose? The main reason I propose cfmodule to developers is that it lets you specify an exact path to a custom tag. No guessing is needed. I'd switch from using name to template. Then there would be zero confusion about which custom tag will run. It may take a little while to update your code base, but it should be worth the effort.

Does anyone else use cfmodule with the name attribute?

Comments

[Add Comment] [Subscribe to Comments]

Another possibility would be to use the <cfimport> method. You can call <cfimport> twice with the same prefix, but from different directories. e.g.

<cfimport taglib="/" prefix="tags>
<cfimport tablib="/#language/" prefix="tags">

<tags:login>

This would allow the sub-directory tag to override the root tag if there was one, I believe.
No - I wouldn't do this. TO me this would add confusion. If you aren't sure which folder would "win", why even risk it? I stand by my original recommendation - specify a full path. It is more typing, but worth the safety.
I'd suggest to Eric that he definitely use the template attribute of cfmodule as Ray suggests. The ability to pass in variables to specify the exact path you want to use means that your application will be much, much more portable. I even pass in the mapping as a variable, myself:

<cfmodule template="#REQUEST.mapping#/CustomTags/tag.cfm"...