I recently came across two misconceptions about the cfmodule tag. The first is that custom tags called via cfmodule can't be used in nested, or 'end' modes. However, this is not the case. In order to wrap a cfmodule call, all you do is add another cfmodule tag, like so:
<cfmodule template="...">
content
</cfmodule >
However, if you have another cfmodule tag inside the pair, CF will think your closing cfmodule tag is really closing the tag on the inside. To address this, simply use <tag/> type notation:
<cfmodule template="...">
content
<cfmodule template="..."/>
</cfmodule >
So - why even use cfmodule? Whenever ColdFusion uses a custom tag, it has to find it first. Since CF supports multiple custom tag directories, the tag can be found in multiple places. If you don't put the custom tag in the same folder as the caller, this could lead to an issue if two custom tags have the same name. For example, on a development box you may have multiple custom tags called authentciate. The cfmodule tag gives you an easy way around this by allowing you to specify a particular relative path, or a mapping in which to find the custom tag. In general, it's probably safest to always use cfmodule, although I don't actually do that msyelf.
Archived Comments
Hi Raymond,
I''m thrilled to see that you''ve started a blog! I''ve always enjoyed your writing in other venues.
A question about your solution:
<cfmodule template="foo">
content
<cfmodule template="bar"/>
</cfmodule >
Won''t the inner tag ("bar") run twice, forcing you to check ExecutionMode in "bar" to prevent that?
I generally prefer what I call the "implicit" syntax of custom tag invocation (<cf_foo>) than the "explicit" syntax (<cfmodule template="foo">). Unfortunately when more than one app is running on the same server (as you note) I too find CF''s search order for finding implicitly-invoked tags lacking. I''d much rather have it search "up" from the invoking template''s directory (like how it looks for application.cfm) rather than "down" through a global directory (even better would be the ability to specify a custom tags directory in CFAPPLICATION).
So I''m usually forced to use the "explicit" syntax, but with that syntax I tend to avoid tag pairs because the only safe way to use them seems to be to *always* test ExecutionMode. Or is that just good CF practice that I should be doing anyway?
Thanks again for blogging!
Jim
P.S. I haven''t worked with CFMX yet, so I don''t know if it has better mechanisms for safely using the implicit syntax when multiple apps reside on the same server. I''d happily ditch the explicit syntax entirely if I could.
Yep - forgot to mention that you would need to check for executionmode - which is not a bad idea in general anyway - so even though it''s more work, I would do it (and it''s one of those things I forget to do myself).
FYI - I see your comment is majorly screwy up there. I''ll look into why things got escaped.
Ok, the bug with the screwy html escaping is fixed now. I also plan on adding a ''remember me'' feature to the comments here, as well as making it email everyone in the ''thread'' when a comment is added.
and you desperately need a permalink feature so you can send a direct link to a post...
:)
AJ