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 »
11,246 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
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
May 24, 2013 at 5:39 PM
Ask Ben: Manually Enforcing Basic HTTP Authorization In ColdFusion
@Adam Oops! My mistake! I hadn't gotten that far in my testing - I'm still baby stepping my way through the process. ... read »
May 24, 2013 at 5:13 PM
Ask Ben: Manually Enforcing Basic HTTP Authorization In ColdFusion
Hi Jason, Thanks for checking up on that, but I still stand firm on my position. :) There are actually two listLast()'s in use, and you're right that the one using a space as a delimiter is fine. ... read »
May 24, 2013 at 4:45 PM
Ask Ben: Manually Enforcing Basic HTTP Authorization In ColdFusion
@Ben I have been lurking your site for quite some time, and haven't stepped up to comment until today. Thanks for all the great info - keep it up! @Adam I believe you are mistaken... as the commen ... read »
May 24, 2013 at 11:21 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@WebManWalking, Ha ha, let's us never speak of justifying "##" notation again :P ... read »
May 24, 2013 at 11:18 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Ben, Ah, so it was indeed how I vaguely remembered it to be: A direct assignment value = users.id[ i ] causes value to retain the sticky datatype of the query column. Although unnecessary in ... read »
May 24, 2013 at 9:11 AM
Preventing Links In Standalone iPhone Applications From Opening In Mobile Safari
@Brandon, Hi, No, I haven't been able to do that. I have just kept it as it is. ... read »
May 23, 2013 at 9:52 PM
Preventing Links In Standalone iPhone Applications From Opening In Mobile Safari
@Muhmmadibn Did you figure out a solution to launching PDFs? I am running into the same issues myself. There is no way to close the PDF or go back once you launch it. Thanks in advance! ... read »
May 23, 2013 at 6:06 PM
The Girl Who Broke My Heart, And Made Me A Better Person
Good day,ladies and gentle men, my name is Dr AMADI the great spell caster in Africa, i have help so many people for different kind of problems,who say there is no solution to problems on earth, that ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools