Skip to main content
Inspiring
April 22, 2008
Question

CFFILE question

  • April 22, 2008
  • 3 replies
  • 1158 views
I'm trying to read a .cfm file on my server with cffile. This is working okay, except that there is some coldfusion code in that file, and when I write it out, it does not work. It just writes out as text in the source code & nothing is executed. Is there a way to make it write the text as actual code, and not just text?

Example:

This topic has been closed for replies.

3 replies

Participating Frequently
April 26, 2008
I would think that you should be getting the articles from the CMS in a different manner than scraping the page but I will asume you have your reasons. So how about this:

<cfsavecontent var="curPage">
<cfinclude template="xyz.cfm" >
</cfsavecontent >

<cfset start = Find('<div id="mainContent">', curPage)>
<cfset stop = Find('mainContent -->', curPage)>
<cfset curPage = Mid(curPage, start, stop)>

It would save two file read/writes.
Inspiring
April 26, 2008
quote:

Originally posted by: jmmorgan
I would think that you should be getting the articles from the CMS in a different manner than scraping the page but I will asume you have your reasons. So how about this:

<cfsavecontent var="curPage">
<cfinclude template="xyz.cfm" >
</cfsavecontent >

<cfset start = Find('<div id="mainContent">', curPage)>
<cfset stop = Find('mainContent -->', curPage)>
<cfset curPage = Mid(curPage, start, stop)>

It would save two file read/writes.

Interesting approach. Where is the part where the code executes?
Participating Frequently
April 26, 2008
Hi Dan -

<cfinclude template="xyz.cfm" >

CF processes and executes all CFML found in files included through a cfinclude tag.

- Jason
Inspiring
April 23, 2008
Since you know how to use cffile,
read the file.
find the part you want and write that to a new file
cfinclude the new file
delete the new file.
Inspiring
April 22, 2008
natg504 wrote:
> Is there a way to make it write the text as actual code, and not
> just text?
>

Umm, maybe with some effort!

But why are you not using the <cfinclude ...> tag which was built just
for this type of purpose? Rather then the <cffile...> tag, which was not?
natg504Author
Inspiring
April 23, 2008
Well, I would use cfinclude, but I only want to get part of the page, not the entire thing. I was using the following code to get just the part of the page between the mainContent div tags.