Using CFContent's Variable Attribute Stops All Further Processing

Posted June 10, 2010 at 8:59 AM by Ben Nadel

Tags: ColdFusion

Yesterday, it was called into question whether or not the use of CFContent's Variable attribute prevented any further processing of the page request. I had suggested it did; but, I wasn't 100% sure. Thinking back, I couldn't remember if I have ever had any code after a CFContent tag that used the Variable attribute (often times, it's the last thing on the page). As such, I thought it'd be easy to whip up a quick test of ColdFusion's expected functionality.

 
 
 
 
 
 
 
 
 
 

The first thing I did was enable session management for the page request. I did this because the ColdFusion livedocs don't expressly refer to page processing - they refer simply to page output:

When you use this attribute [Variable], any other output on the current CFML page is ignored; only the contents of the file are sent to the client.

This is a bit ambiguous as to whether it refers to code execution or just to page output. By enabling session management, we can test session value updates even if the generated output is not being streamed to the client.

Application.cfc

  • <cfcomponent
  • output="false"
  • hint="I define the applications settinsg and event handlers.">
  •  
  • <!--- Define application settings. --->
  • <cfset this.applicationTimeout = createTimeSpan( 0, 0, 5, 0 ) />
  • <cfset this.sessionManagement = true />
  • <cfset this.sessionTimeout = createTimeSpan( 0, 0, 0, 20 ) />
  •  
  • </cfcomponent>

Now that session management is enabled, I created a page that generated page output and updated session values both before and after a CFContent tag:

  • <!---
  • Param the session hit counter to make sure that output
  • is not the only thing that gets altered.
  • --->
  • <cfparam name="session.hitCount" type="numeric" default="0" />
  •  
  • <!---
  • Create a path to the log file so that we can track the
  • parts of the page that actually process.
  • --->
  • <cfset logFilePath = expandPath( "./log.htm" ) />
  •  
  •  
  • <!--- ---------------------------------------------------- --->
  • <!--- ---------------------------------------------------- --->
  •  
  •  
  • <!--- Increment the hit count. --->
  • <cfset session.hitCount++ />
  •  
  • <!--- Log that we made it this far in the page request. --->
  • <cfdump
  • var="Before CFContent (#session.hitCount#)"
  • output="#logFilePath#"
  • />
  •  
  •  
  • <!--- ---------------------------------------------------- --->
  • <!--- ---------------------------------------------------- --->
  •  
  •  
  • <!---
  • Create a binary variable of a text value and stream it
  • to the client using the Variable attribute.
  • --->
  • <cfcontent
  • type="text/plain"
  • variable="#toBinary( toBase64( 'Hey there buddy!' ) )#"
  • />
  •  
  •  
  • <!--- ---------------------------------------------------- --->
  • <!--- ---------------------------------------------------- --->
  •  
  •  
  • <!--- Increment the hit count. --->
  • <cfset session.hitCount++ />
  •  
  • <!--- Log that we made it this far in the page request. --->
  • <cfdump
  • var="After CFContent (#session.hitCount#)"
  • output="#logFilePath#"
  • />

As you can see, I am incrementing and logging the session's hitCount variable both before and after the CFContent tag. In this way, I can see if the session value is updated post-CFContent even if the "output" generated by the CFDump tag is not rendered. After refreshing the page a few times, here's what the log file contains:

Before CFContent (1)
***********************************************************

Before CFContent (2)
***********************************************************

Before CFContent (3)
***********************************************************

Before CFContent (4)
***********************************************************

As you can see, not only does the second CFDump tag never render to the log file, the incrementing session hitCount demonstrates that no code was executed after the CFContent tag.

I had thought that this was the expected CFContent behavior, so it's nice to see ColdFusion work this way. That said, I should remind people that this is only for a very specific use-case of CFContent - the Variable attribute (as well at the File attribute); all other uses of the CFContent tag will simply affect the response headers and the existing output buffer, allowing the rest of the page to process normally.




Reader Comments

Jun 10, 2010 at 5:07 PM // reply »
39 Comments

What about an onRequestEnd.cfm, or OnRequestEnd() in the application.cfc?


Jun 10, 2010 at 5:13 PM // reply »
10,743 Comments

@Tim,

I'm 99% sure that those are no executed either; but I will check and get back to you.


Jun 10, 2010 at 10:29 PM // reply »
2 Comments

Hi Ben,

what happened if any error occured.............


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
May 16, 2012 at 8:18 PM
Best Of ColdFusion 10 Contest Entry - HTML Email Utility
Just found this, looks good! I'm trying to run it on local, it's the 64bit version and I'm experiencing horrible lag. On average the generate.cfm processes the content change in 60-90 seconds. I've ... read »
May 16, 2012 at 6:40 PM
Maintaining Sessions Across Multiple ColdFusion CFHttp Requests
I am trying to integrate this CFHTTPsession into an application that will log into zeekrewards.com to post ads and I am not having any luck. The code works perfectly for logging into other websites, ... read »
May 16, 2012 at 2:44 PM
Creating A Sometimes-Fixed-Position Element With jQuery
Thank you, very useful technique! Worked like a charm. ... read »
May 16, 2012 at 1:58 PM
Movies As A Religious Experience
Acting can, in a way, ruin the movie-goer's experience. I used to be able to get so caught up in movies and their plots, and totally engaged. But lately, I haven't been able to as much with a lot o ... read »
May 16, 2012 at 1:52 PM
The Science Of Optimal Post-Exercise Nutrition
children of this age eat very less vegetables so u can opt for salads they will like it also carrot ,cucumber,onion and as far as pulses are concerned u can boil them ,give him along with mashed rice ... read »
May 16, 2012 at 1:34 PM
Strange ColdFusion JRUN Stack Overflow Error
Hey, Recently I updated my jrun4 using the latest updater 7 and now i am having memory issues :(:(:( any help is appreciated ... read »
May 16, 2012 at 9:56 AM
ColdFusion 10 Beta, Apache Tomcat, And Symbolic Links On Mac OSX
Hi, Now that ColdFusion 10 is out I have stumbled over this as well and I cannot figure out the proper solution. We're running virtual hosts via Apache2; the ColdFusion-applications store their fil ... read »
May 15, 2012 at 6:03 PM
Movies As A Religious Experience
@Ben, I don't know whether you'd consider this a religious observation, but it seems to me, in a sense, movies multiply how many lives we get to have. Each movie is like a little extra life we get ... read »