Bug in ColdFusion's cfcontent within CustomTag execution end
I was working on a ColdFusion custom tag this afternoon, that is to throw an error if tag is not properly constructed. In order to clean out the output, I'm using the following ColdFusion code snippet to clear the output buffer:
<cfcontent reset="true" />
This usually works great, but for some reason the output was always been displayed twice. The code was not actually executing twice, just being displayed in the output stream twice when the custom tag was in the "end" execution method.
To illustrate this problem, save the following as "contentBug.cfm":
<cfif (thisTag.executionMode is "start")> <cfparam name="attributes.reset" type="boolean" default="false" /> <!---// if we have an end tag, stop processing now (the rest of the code will be run on the tag end) //---> <cfif thisTag.hasEndTag> <cfexit method="exitTemplate" /> </cfif> </cfif> <cfif attributes.reset><cfcontent reset="true" /></cfif> <cfoutput><h1>test!</h1></cfoutput> <cfdump var="#thisTag#"> <cfabort />
Now save the following in a file called "test.cfm":
<cf_contentBug reset="true" />
NOTE:Pay attention to the tag syntax, the "/>" makes the code execute in the "end" execution method where the bug reveals itself.
When you run the test.cfm template, you'll see the following output:
Note that the "test!" data outputted twice. If you change the "reset" attribute to "false" or change the code to <cf_contentBug reset="true"> (no ending slash) the code is only generated once.
This bug shows up in both ColdFusion v8.0.1 and v9.0.
If I find a workaround (other than not using <cfcontent reset="true" /> in my code) I'll make sure to update this post!
Comments
<cfif (thisTag.executionMode is "end")>
. . . . <cfcontent reset="true" />
. . . . Hello in Tag!
. . . . <cfabort />
</cfif>
This will duplicate the output. Remove the CFContent OR the CFAbort and it works fine. Have them both, and you definitely get some sort of bug.
<cf_contentBug reset="true" />
Should work great
That's the point of the bug. For my actual code, the end execution is required. This is just a simplified example to show off the issue. The point is it should work, but doesn't.

<cfexit method="exittag" />
"ExitTemplate" simply stops the current mode of execution, not the entire tag.
That said, something still feels "buggy" though because if you exit the template (hault the START mode of execution), you still shouldn't see the output twice - it would only jump to the body (which you don't have) and then on to the END mode execution, which would only show once. Hmmm, I think.