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!