Awesome ColdFusion Custom Tag Tip : CFExit Method / Loop

Posted October 13, 2006 at 6:05 PM by Ben Nadel

Tags: ColdFusion

I just randomly happened upon this great ColdFusion custom tag tip over on Doug Hughes' site. I never realized this, but there is a LOOP value for the CFExit tag's method attribute:

  • <cfexit method="LOOP" />

Who knew? Apparently not me. Thought I would pass it on here in case anyone else missed it. Anyway now that Doug has armed me, it's time to start the experimenting :) Sweeeeeet.




Reader Comments

Oct 16, 2006 at 9:56 AM // reply »
171 Comments

It's important to know the difference between <cfexit method="loop" /> and <cfbreak />.

<cfbreak /> is designed to exit out of a loop in the current template.

<cfexit method="loop" /> is designed for custom tags running in the "end" execution mode and it continues processing from first child in calling template.


Oct 16, 2006 at 10:04 AM // reply »
11,314 Comments

Dan,

I have to admit, when I first read about the <cfexit method="LOOP" /> I was pretty pumped up... but when I started to think about how I could experiment with it, I came up short. I have seen examples, but didn't really understand them. To me, if I am going to iterate over something, I might as well just pass it into a function or a custom tag and do the iteration internally. I am not sure what advantage physically looping the tag would do.

I thought maybe it would be cool to be able to loop over something and have a custom "renderer" for each indexed item... but then I thought, why would I go through the overhead of a custom tag... why not just loop over it manually via a CFLoop of some sort and then use a custom tag renderer.

Anyway, it's still interesting and I want to learn how to leverage it well.


Jan 29, 2008 at 8:07 PM // reply »
15 Comments

Seems like it should be method="endTag", or something. I just ran into a situation where I'd like to be able to exit the current iteration without breaking the loop. Here's the idea:

<cfloop from="1" to="20" index="i">
Process some stuff
<cftry>
Try something here that may cause an error
<cfcatch>
Ooh, error. It's not critical, but we can't continue. So we'll simply log it and alert someone.
<cflog>
Exit this iteration and continue processing
<cfexit method="loop">
</cfcatch>
</cftry>
If the above try/catch was successful, we'll do some more stuff.
</cfloop>

I could wrap cfif tags around everything, but that's ugly ;)


Jan 29, 2008 at 8:17 PM // reply »
15 Comments

Correction... I should have said, I could wrap CFTRY tags around everything inside the loop.


Jan 30, 2008 at 7:58 AM // reply »
11,314 Comments

@Brad,

I see. You want something like a CFContinue tag. I have seen many people request something like that.

But, be careful; CFExit has to do with template-level execution, not loop execution. I think you are a bit confused as to what it is supposed to be doing with a custom tag.


Jan 30, 2008 at 1:15 PM // reply »
15 Comments

Yeah. I'm clear on what it does. I use CFExist quite often to exit tags and templates. I just thought method="loop" is a little misleading. It's funny, I've been using CF for 7 years, and I've never used a custom tag to loop over something.


Jan 30, 2008 at 1:26 PM // reply »
11,314 Comments

@Brad,

Yeah, I didn't use it for the longest time. The only reason I have used it to -date is to create custom CFLoop-style tags.


Apr 17, 2008 at 1:16 PM // reply »
2 Comments

I tested the cfexit on a loop and would like to confirm that it exits the template, not the loop. Perhpas the author meant to say that it exits the loop as well as the page.


Apr 17, 2008 at 1:57 PM // reply »
2 Comments

Just wanted to add that I meant without specifying the method in the tag as was introduced here.


Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
Jun 18, 2013 at 9:20 PM
Mapping AngularJS Routes Onto URL Parameters And Client-Side Events
I couldn't find examples of passing multiple arguments using the when() routing statement so figured out through trial and error that you can pass multiple arguments using the following format: .whe ... read »
Jun 18, 2013 at 3:39 PM
Experimenting With The Amazon Simple Storage Service (S3) API Using ColdFusion
Hi Ben, THANKS! While not bleeding edge, it is new to me & I like learning new things every day! ... read »
Jun 18, 2013 at 12:30 PM
Disabling Auto-Correct And Auto-Capitalize Features On iPhone Inputs
Also spellcheck="false" should be mentioned as part of html5 specs ... read »
Jun 18, 2013 at 8:40 AM
Using Named Functions Within Self-Executing Function Blocks In Javascript
Hi Ben, you forgot to mention the most important thing for named self-executing functions - they can be referenced by name ONLY inside their execution context (which is parens in this case), it mean ... read »
dee
Jun 18, 2013 at 7:01 AM
My Safari Browser SQLite Database Hello World Example
hai ben, this program is really good i could understand the concept but i dint know how to save it and how to open it as you have done in the video can u give that details pls ... read »
Jun 18, 2013 at 6:04 AM
Clearing Inline CSS Properties With jQuery
Thanks a lot for for post! It helped me a lot... after being stuck since 24 hrs.. found solution from your post. Thanks again! ... read »
Jun 18, 2013 at 2:31 AM
SOTR 2013 - The Best Conference I Never Went To
I keep watching it, should keep me happily distracted until SotR14 ;) ... read »
Jun 17, 2013 at 9:45 PM
What If All User Interface (UI) Data Came In Reports?
@Jonah, As I was reading what you wrote, it occurred to me that maybe I do something similar to that in some of my client-side code. In an application I'm working on, there are a bunch of unrelated ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools