I was under the impression that when you included a template via the page context Include() method, the template was simply included as a text file.
<!--- Include page without parsing. ---> <cfset GetPageContext().Include( "./include.cfm" ) />
I touched upon this in my entry about reading in files using CFInclude. Charlie Arehart pointed out that this was, in fact, quite incorrect. He pointed out that not only does the included file get parsed by ColdFusion, is also gets treated as a regular page call complete with Application.cfc/cfm pre-page processing.
I believe him, but just to see it for myself, I set up a little test. First, I set up a simple Application.cfm template to help test pre-page processing. The Application.cfm simply defines the application and increments a page request counter:
<!--- Define application. ---> <cfapplication name="CFInclude Test" applicationtimeout="#CreateTimeSpan( 0, 0, 10, 0 )#" /> <!--- Param the counter to keep track of how many requests run through the application page pre processing. ---> <cfparam name="APPLICATION.RequestCount" type="numeric" default="0" /> <!--- Add one to the request count. ---> <cfset APPLICATION.RequestCount = (APPLICATION.RequestCount + 1) />
Then, I set up a single page that including a template using both the traditional ColdFusion CFInclude tag as well as the GetPageContext().Include() methodology:
<!--- Write this main request to file. ---> <cffile action="APPEND" file="#ExpandPath( './trace.txt' )#" output="Request #APPLICATION.RequestCount#" addnewline="true" fixnewline="true" /> <!--- Include file. ---> <cfinclude template="include.cfm" /> <!--- Include file. ---> <cfset GetPageContext().Include( "include.cfm" ) />
As you can see, I am tracing my page request to a text file, trace.txt. This way I can see which page request each include is being part of. Then I have the simple include.cfm template:
<!--- Figure out if we are running the CFInclude version of this template. Check the base tag list to determine what text we should output. ---> <cfif ListFind( GetBaseTagList(), "CFINCLUDE" )> <!--- Set mode text. ---> <cfset strMode = "CFInclude" /> <cfelse> <!--- Set mode text. ---> <cfset strMode = "Include()" /> </cfif> <!--- Try to write this request to file. ---> <cffile action="APPEND" file="#ExpandPath( './trace.txt' )#" output="...Included via #strMode# during request #APPLICATION.RequestCount#" addnewline="true" fixnewline="true" />
As you can see, I am using the base tag list to determine which methodology was used to include the current tag. If the base tag list contains CFINCLUDE, then I know that I am using the standard ColdFusion CFInclude tag. If not, then I know that I am using the GetPageContext().Include() methodology.
By my previous assumptions, the GetPageContext().Include() methodology should not even write to the trace file since it is not being parsed. However, when I looked at the trace file, I get something very different:
...Included via CFInclude during request 38
...Included via Include() during request 39
...Included via CFInclude during request 40
...Included via Include() during request 41
...Included via CFInclude during request 42
...Included via Include() during request 43
...Included via CFInclude during request 44
...Included via Include() during request 45
I was completely wrong. And, it looks like Charlie Arehart was dead on the money. As you can see, the template, when operating under a ColdFusion CFInclude tag, runs in the same page request as its parent template. However, as you can see by the APPLIACTION.RequestCount output, the include, when included via the page context not only outputs to the trace file, indicating that it does in fact get parsed, it is also incrementing the APPLIACTION.RequestCount variable indicating that it does in fact get treated as its own page request (complete with pre-page processing).
This is some very good information to know. Sorry to all of you out there that I mislead about the page context Include() method. Thanks Charlie for showing me the light - you the man (this is adding to your existing man-factor acquired via your CFHttp / CGI variable comments back in 2004)
I also noticed that at the bottom of my page I was getting a 500 null error. Ugg, the dreaded 500 null error! I can only assume that this is happening because I am including one page request inside of another and come one people, that just doesn't make any sense - why would I do that??
Want to use code from this post? Check out the license.