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

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? </blockquote> 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: <cfmodule name="en.login"> Or - if the language was determined at runtime: <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?
Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Comments