QuackFuzed.com is the personal ColdFusion coding blog of Matt Quackenbush. It exists primarily as a place for the author to learn, and hopefully to assist others in learning and/or avoiding some of the same pitfalls and mistakes. (Quack certainly makes enough mistakes daily to make up for the entire ColdFusion community.)
<cfexit method="exittag" /> QuackFuzion
Posted on January 5, 2008 at 1:32 AM in ColdFusion
While I've been writing ColdFusion for over 10 years now, I am a relative newcomer to the world of writing my own custom tags. I know, odd; but it is what it is. On occasion, I run into a particular behavior with <cfexit /> that perplexes me greatly, and I'm hoping that someone can help shed some light on it for me.
Latest Articles
- No recent entries.
Eventually something really brilliant and witty will appear right here.
Categories
- ColdBox (21) [RSS]
- ColdFusion (92) [RSS]
- Fusebox (3) [RSS]
- General (22) [RSS]
- jQuery (15) [RSS]
- Kalendar (1) [RSS]
- Linux (1) [RSS]
- Mura CMS (1) [RSS]
- Railo (1) [RSS]
- Rants (5) [RSS]
- Transfer (8) [RSS]
- Uni-Form Tag Library (36) [RSS]



On 1/5/08 at 6:31 AM, Michael Sharman said:
cfexit has 3 possible "methods":
1. ExitTag
2. ExitTemplate
3. Loop
When you call cfexit method="exitTag" in either "start" or "end" mode, ColdFusion will exit the custom tag and continue processing AFTER the end tag.
ExitTemplate jumps to the 'inactive mode' (in between start and end tags) if in start mode. If in end mode then it exits the custom tag and continue processing after the end tag.
Loop doesn't work if in start mode, if in end mode it jumps back to inactive mode (good when you have nested child custom tags).
Hope that helps!
On 1/5/08 at 8:57 AM, todd sharp said:
<cfif thisTag.executionMode eq 'start'>
do stuff...
<!--- if the tag *requires* an end tag --->
<cfif not thisTag.hasEndTag>
<cfthrow message="You need to close this tag dude!" />
</cfif>
<cfelse>
do something (or nothing)...
</cfif>
On 1/5/08 at 11:16 AM, Tony Petruzzi said:
Instead of doing the thistag.executionmode check like so:
<cfif thisTag.executionMode IS NOT "start">
<cfexit method="exittag" />
</cfif>
Just make <cfexit method="exittag" /> the last line of your custom tag.
Benefits of doing the way I'm suggesting:
1) less code so it looks cleaner
2) easier to remember
3) you don't have to use a condition so it executes faster (like 1ms, but what the heck)
On 1/5/08 at 3:36 PM, Matt Quackenbush said:
@ Todd/Tony - Thanks for the suggestions. Both make a lot of sense, and I shall likely use both of them in appropriate circumstances.
On 1/5/08 at 9:45 PM, Michael Sharman said:
Or anything else which might do this in the custom tag?
On 1/6/08 at 12:16 AM, tony petruzzi said:
For instance: I normally have a custom tag I use for layout and then some helper custom tags for form stuff. I've found in the past that I had to make sure that I was closing them correctly or weird things would happen, like the stuff you're describing.
On 1/6/08 at 7:05 PM, Matt Quackenbush said:
@ Tony - I'm not using any nested tags.
I've attached a zip file to the post with a couple of demo files. cfexit.cfm is the main template, and states.cfm is the custom tag.
On 1/6/08 at 7:27 PM, Michael Sharman said:
I believe it's because of your whitespace management.
At the top of your states.cfm you have <cfsetting enablecfoutputonly="yes" />, but if you exit the custom tag you still have this setting enabled which will therefore supress any output you have.
You can either put cfoutput around everything in the 'caller' page or more likely re-arrange your custom tag's cfsetting.
Hope that helps
On 1/6/08 at 7:37 PM, Matt Quackenbush said:
Thanks to everyone who took a look at it.
On 2/11/08 at 1:04 AM, ike said:
With regard to cfexit specifically though, if I have a custom tag that's not supposed to have an end tag, I'll always just put the cfexit at the end of the tag without the conditional around it -- that way it just exits at the end of the "start" mode instead of checking to see if it's in end mode first. And if you put the exit after your cfsetting where you re-enable the enablecfoutputonly flag, then that'll avoid this particular wierdness.