ColdFusion templates -- NOT relying on CFINCLUDE

larry98765

Registered
Hi All,

I'd consider myself beginner/intermediate with ColdFusion. I use template includes constantly to build pages on-the-fly. But I'm hoping someone can put me in the right direction regarding this question:

I'd like my CF app to ASSUME I want certain things on every page -- i.e. the header, the meta tags, the footer, the nav bar, etc.

In other words, I'd like to be able to make my individual pages only have the necessary HTML tags for the main section, so an ENTIRE template page might look like this:

<title>The title of this page</title>

<div id="content">
<h1>Yadda yadda</h1>
<p>Paragraph 1, etc</p>
<p>Paragraph 2, etc</p>
</div>

and that would be it for the page. Then, I'd like CF to assume I want all the other tags, and despite there being no CF Includes in my templates, I'd like CF to "wrap" the necessary stuff around it. (i.e. the html, head, body, meta, navigation elements, style sheet embeds, etc.)

Does this make sense? Anyone have any ideas for me?

Thanks in advance!
 
Yes you can do this. Check here:
http://www.johnwbartlett.com/CF_tipsNtricks/index.cfm?TopicID=33

Basically you can make use of the "application framework" and use the special "Aplication.cfm", and "OnRequestEnd.cfm" files to do this. These two files will execute at the beginning and end on any file which they are in the same directory as.

Although this is a solution, I prefer the use of <cfinclude>. I like to be in control of what code is executed. I would rather not let the CF engine make that decision for me.

Hope this helps.
 
Teamteama --

As per your recommendation, I read the article and it looks easy enough.

Many thanks for pointing me in the right direction! :)
 
It works great. I'd like, however, to take it a step further: as it is now, I can use the Application.cfm file to insert everything up to my content, which I include in div tags in the file requested by the user (let's call it test.cfm). Then, the OnRequestEnd.cfm file includes the footer and the closing body and html tags.

The only caveat is the page title. I'd like to be able to declare that within test.cfm as well, and I'd like to avoid having to include everything AFTER title and BEFORE the content (i.e. the closing head and opening body tag) in test.cfm.

I know that doesn't sound like all that much of a benefit, but I'm trying to separate all my default content from my page-specific content, while still using HTML (or XML or whatever) rather than a database-driven solution.
 
Back
Top