Skip to main content
November 28, 2008
Question

Including CFML in generated static pages

  • November 28, 2008
  • 3 replies
  • 1204 views
How can I include CFML into generated static pages. That is, I want to use Coldfusion to generate and save the pages but have some CFML in the page to be executed when the generated page is later served from the website.

Thanks,
Magnus
    This topic has been closed for replies.

    3 replies

    December 1, 2008
    With my solution it does exactly what you want. You create the whatever.cfm with an editor ONCE. You create the "static" contents daily or whenever in any manner you choose (e.g. say PHP if not CF) which maybe takes 15 minutes to run so that's why you want to run this only occasionally and not everytime on demand.

    The user requests whatever.cfm and it puts your dynamically generated header and footer around your "static" stuff and serves it to the user.
    December 18, 2008
    quote:

    What is the difference between a page being generated and a page being served? Unless I'm missing something, you want to both not run the code and run it.


    To make myself clearer:
    A. I am using a CFM template to query a database, does a bunch of number crunching and dynamically creates a page to to view the results. Pretty standard stuff. This is generating the file.
    B. But then, the output of this template is saved as a file and CFcontent is used rename the file. This file is saved on the webserver so it can be served up as needed.
    In other words, the CFM template is used to generate a new file that is published on the website.

    I am doing this now and in general it works fine.The problem is that the new file contains only HTML and the included headers and footer are part of the new file and any future changes to the headers and footers isn't reflected in these files.

    (Aside: This step is done once a month as part of a human intervention step to clean up the user supplied data. The data is date specific and represents a period in time. As time moves on the results for a specific time period will not change so they are suitable for presentation in a static page.)

    All I want do is make it so that regardless of when a page is generated it will include the current headers and footers. I think this will do it (thanks Adam), although I haven't tested it yet.

    quote:

    Sure. The only trick to it is that to stop the CF engine from seeing the tags as CFML the first time it processes it is to separate the open angle bracket from the following "CF", eg: <cfset myCfmlString = "<" & 'cfinclude template="/path/to/file.cfm">'> So if you then want to simply output that for some reason, you just do this: <cfoutput>#myCfmlString#</cfoutput> Which will output: <cfinclude template="/path/to/file.cfm"> (ie: exactly that).


    I may abandon this approach altogether since even it I can keep the headers and footers up to date I will still be stuck with the static presentation/layout of the data if I ever want to change that. On the other hand a strictly dynamic solution will present its own hassles if the way in which the start and end dates of each period are determined changed.

    Thanks for everyone's input.

    Magnus
    December 1, 2008
    How about this....

    create whatever.cfm

    <CFINCLUDE your header>
    <CFHTTP url="your static page">
    <CFOUTPUT>#cfhttp.fileContent#</CFOUTPUT>
    <CFINCLUDE your footer>
    November 28, 2008
    I'm not sure I understand what you mean. Could you be a bit more clear?

    Either way, I'm sure it'll end up using the CFSAVECONTENT, CFFILE and htmlEditFormat tags and function somewhere along the line.

    Thanks,
    Mikey.
    November 29, 2008
    I currently generate a page which includes date from a DB, etc. The generated output of this page is saved as a static html page. This page is placed on the website and accessed as a html page. The problem is all the content is static as of the time of generation. In particular this means trhat headers and footers are hard-coded in rather than incorporated by includes.

    What I want to do is is have the generated page output by Coldfusion have both CFML and HTML such as the simplified attached code. Now, when this page is served is uses included headers rather than hard-coded ones. This is a bit of a simplification of what I want to do but if I can get this Ican get the rest of the way.