Ben Nadel
On User Experience (UX) Design, JavaScript, ColdFusion, Node.js, Life, and Love.
Ben Nadel at cf.Objective() 2013 (Bloomington, MN) with: Jason Dean
Ben Nadel at cf.Objective() 2013 (Bloomington, MN) with: Jason Dean@JasonPDean )

I Don't Understand ColdFusion GetPageContext() And Include()

By Ben Nadel on
Tags: ColdFusion

I was pulling my hair out trying to figure out an error I was getting with the following code:

  • <!--- Include public style sheet. --->
  • <cfset GetPageContext().Include( "../../../linked/css/main.css" ) />

This line of code kept throwing the error:

After literally an hour and a half of playing around with "../" combinations and outputting FileExists() results, I switched over to using a CFInclude tag:

  • <!--- Include public style sheet. --->
  • <cfinclude template="../../../linked/css/main.css" />

For some reason, this include works, and the include method of the GetPageContext() servlet does NOT work. I have no idea what this means. As I am not a professional Java programmer, I am not familiar with servlets and context objects. I don't know if it has something to do with web-visibility. I know that the include above were crossing over a virtual directory (an admin area was pulling the CSS file from the public site and the admin was in a virtual directory).

Who knows. I tried to Google some information about page context and I came up with this Java class, but that doesn't really help me understand. Maybe someone out there can help.

As part of my mentality, I was doing it this way so that the main.css file would be included without being parsed. As far as I know, a CFInclude tag will actually parse the file looking for ColdFusion code (even in a CSS file). I had no need to parse the file and was told that the Include() method would not do so.

Looking For A New Job?

100% of job board revenue is donated to Kiva. Loans that change livesFind out more »

Reader Comments

"a CFInclude tag will actually parse the file looking for ColdFusion code (even in a CSS file)"

It doesn't unless it's a file with an extension that equates to a Coldfusion template i.e .cfm.

Try it yourself, cfinclude a css file. If CF was trying to parse the file you'd get errors being thrown when it encounters # symbols on styling blocks.


Please take a look at the demo that I have set up. I think you are confused about evaluation of # signs vs. parsing of page looking for ColdFusion tags.