• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

CFFILE question

Explorer ,
Apr 22, 2008 Apr 22, 2008

Copy link to clipboard

Copied

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:

TOPICS
Advanced techniques

Views

1.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 22, 2008 Apr 22, 2008

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 23, 2008 Apr 23, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 23, 2008 Apr 23, 2008

Copy link to clipboard

Copied

natg504 wrote:
> 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.
>
>
>
> <!--- get only the part of the page between the mainContent section --->
> <cfset start = Find('<div id="mainContent">', curPage)>
> <cfset stop = Find('mainContent -->', curPage)>
> <cfset curPage = Mid(curPage, start, stop)>
>


If this is what you have to work with. You are going to want to look at
the evaluate() function which says run this string as a chunk of code.
But it could be a bit tricky.

If I could do so, I would explore the option of isolating that section
of code in some manner that can be used in both places it needs to be
used. That would be the simplest and most scalable solution.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 23, 2008 Apr 23, 2008

Copy link to clipboard

Copied

> <!--- get only the part of the page between the mainContent section --->
> <cfset start = Find('<div id="mainContent">', curPage)>
> <cfset stop = Find('mainContent -->', curPage)>
> <cfset curPage = Mid(curPage, start, stop)>

Dan has put forward a suggestion that will work for this.

However - if this is what you need to be doing - I would be questioning the
entire process, not simply the last step of it.

From where I'm sitting, and with the info you've provided, what you are
trying to do is *really* *grim*, and _I think_ you should be trying to
reconsider your approach here.

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 24, 2008 Apr 24, 2008

Copy link to clipboard

Copied

Adam,

If you have any suggestions on another approach to take, that would be helpful. The problem is that I need to display content from the other .cfm pages, and that content is not in a database, so I'm trying to figure out a way to get it & display it. I don't have the ability to change the database, so I can't add the content to the database & just do a query. Also, I can't grab the entire page with a cfinclude because they're created with templates & I would have errors because of things being defined twice. The database does include a field with a link to the .cfm page, but that is all I have to use. I want to grab a section of all those .cfm pages and display them all on the same page.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 24, 2008 Apr 24, 2008

Copy link to clipboard

Copied

natg504 wrote:
> Adam,
>
> If you have any suggestions on another approach to take, that would be
> helpful. The problem is that I need to display content from the other .cfm
> pages, and that content is not in a database, so I'm trying to figure out a way
> to get it & display it. I don't have the ability to change the database, so I
> can't add the content to the database & just do a query. Also, I can't grab
> the entire page with a cfinclude because they're created with templates & I
> would have errors because of things being defined twice. The database does
> include a field with a link to the .cfm page, but that is all I have to use. I
> want to grab a section of all those .cfm pages and display them all on the same
> page.
>
>
>


Can you redesign the original page? Pull out this common section into
it's own file that is then <cfinclude... it into both places?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 24, 2008 Apr 24, 2008

Copy link to clipboard

Copied

> The problem is that I need to display content from the other .cfm
> pages, and that content is not in a database, so I'm trying to figure out a way
> to get it & display it.

Why do you need to do this? I'm not being obtuse (well: not *meaning* to
be obtuse ;-), just trying to work out where you're coming from, so I can
suggest how you might try to effect a solution.

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 24, 2008 Apr 24, 2008

Copy link to clipboard

Copied

The site uses a content management system, so I'm limited on the changes I can make to any pages. People enter the text & html for an article into a form & create a .cfm page from that using the cms. What I'm trying to do is dynamically get all of the articles from a single month & put them on to one page. I'm using the cfdocument tag to make that page a pdf, so that monthly issues of this publication will be automatically generated for users to download.

I can figure out what articles to get because there is a database with a date & url for each article. The rest of the article content is not in a database though.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 24, 2008 Apr 24, 2008

Copy link to clipboard

Copied

Right, I see.

Well all you can really do then, I guess, is proceed the way you started.
Sorry to sidetrack you a bit, but sometimes people do some really weird
things when the actual solution is easier, so sometime sit's better to coax
a bit more info out of them to see what's going on.

So, anyhow, you've used find() to extract the boundaries of the patch of
content that you need; use mid() to pull it out, write it to a temporary
file and then <cfinclude> that file. Delete the temp file afterwards.

One thing to bear in mind here - and where you were going wrong -
*outputting* the CF code is not the same as executing it. You need to
remember that it's not the CFML source code that's executed; it's compiled
into byte code first by the CF server, then the byte code is executed. So
you need to pass the source code to the CF server, not to the web browser.
Which is why you need to <cfinclude> it (or <cfmodule>, or any other way
one can call a file to execute it. Just not simply outputting it.

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 23, 2008 Apr 23, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 25, 2008 Apr 25, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 25, 2008 Apr 25, 2008

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 25, 2008 Apr 25, 2008

Copy link to clipboard

Copied

LATEST
Hi Dan -

<cfinclude template="xyz.cfm" >

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

- Jason

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation