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 »
160 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 »
10,640 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 »
10,640 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 »
10,640 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
InVision App - Prototyping Made Beautiful With Prototyping Tools Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
Feb 12, 2012 at 3:37 AM
Learning ColdFusion 8: CFImage Part III - Watermarks And Transparency
Hi Ben, Just to ask currently it is placed bottom right corner, if i need to replace the same rendered image on the bottom left side or in the bottom center, how that can be calculated. bottom ce ... read »
Feb 11, 2012 at 9:29 PM
Use jQuery's SlideDown() With Fixed-Width Elements To Prevent Jumping
I can't say how glad I am that I found your post. Thank you very much. ... read »
Feb 10, 2012 at 7:21 PM
jQuery AJAX Strips Script Tags And Inserts Them After Parent-Most Elements
Update! Instead of $(eval(options.insertAfter)).after(data['insertData']); I now use: var ajaxNode = document.createElement('span'); var parent = $(eval(options.insertAfter))[0].parentNode; ... read »
Feb 10, 2012 at 6:18 PM
jQuery AJAX Strips Script Tags And Inserts Them After Parent-Most Elements
encountered this same, what I consider, jQuery bug last week. I'm building a site in which I load some content via AJAX. This content contains Linkedin share button placeholders which Linkedin API ne ... read »
Feb 10, 2012 at 11:30 AM
Cross-Origin Resource Sharing (CORS) AJAX Requests Between jQuery And Node.js
After you understand the concepts here, this is an awesome cheatsheet for enabling CORS in just about anything http://enable-cors.org/ ... read »
JM
Feb 10, 2012 at 9:10 AM
My Safari Browser SQLite Database Hello World Example
@Amy, Here is a very good tutorial on how to use JOIN: http://www.sqltutorial.org/sqljoin-innerjoin.aspx ... read »
Feb 10, 2012 at 4:42 AM
Building A Twitter-Inspired RESTful API Architecture In ColdFusion
This is great, very useful Ben. I spotted a small typo in the api.cgm listing: <cfthrow type="Unauthroized" /> Cheers Stefan ... read »
Feb 9, 2012 at 10:35 PM
CFDirectory Filtering Uses Pipe Character For Multiple Filters (Thanks Steve Withington)
I was wondering if there would be a filter you could apply so that you got everything but what you included in the filter. As in show me all docs that are not a .pdf. ... read »