No, It's not. Though you may be keeping your code in includes, you're still
using Application.cfm and onrequestend.cfm to call the includes. You might
as well be writing the code directly to application.cfm and
onrequestend.cfm, because coldfusion processes the contents of an include AS
IF THEY BELONG IN THE PAGE THAT CALLS THEM (sorry for the shouting, it was
for emphasis only). So, after the server has done its work, calling the
includes from these pages amounts to the same thing.
What you need to do, in order to be consistent with how application.cfm and
onrequestend.cfm are supposed to be used, is to write a custom tag that
contains your header and your footer and call the tag specifically around
all of your display templates.
For example:
Mylookandfeel_customtag.cfm
<cfswitch expression="#thistag.executionmode#">
<cfcase value="start">
<html><head><title></title></head><body>
<table><tr><td>
</cfcase>
<!---nothing goes here --->
<cfcase value="end">
</td></tr></table>
</body></html>
</cfcase>
</cfswitch>
Myactualpage.cfm
<cfmodule template="mylookandfeel_customtag.cfm">
This is the actual code on my page. Yay, aren't I all pretty and
formatted!
</cfmodule>
Obviously this is just a toy example, but it illustrates the point. You
store the formatting in mylookandfeel_customtaglcfm. You split the look in
feel in half, determining where the body of the page will lie and everything
above that point is in the fist case statement while everything below that
point lies in the second case statement.
On the page where your acutual content lies, you use a cfmodule tag to call
the wrapper. Make sure the path you use in the template attribute is
correct. In my little "toy" example I assume that I've saved the custom tag
in the same directory as the page that will call it. This may not be the
best site design, of course. If you store your tags in a separate central
location, use a coldfusion mapping to create a path to the folder where it's
located and call the mapping in the template attribute.
Now you may ask, why is it such a bad, horrible thing to use application.cfm
and onrequestend.cfm like you are? After all, it's so much easier to put
the header and footer includes there ONCE rather than having to specifically
call that pesky custom tag everything you want to put a table and some
buttons around things.
Well, the thing is if you put that kind of code in application.cfm, you'll
be calling it EVERY time youc all ANY template.
For example, lets say that in your page you are calling a couple of
includes... Maybe one has a udf library. Maybe another has a whole bunch of
queries. Maybe another has a calendar or something reusable like that. In
that case you will be calling application.cfm 4 times... Not just once,
because every time one of those includes gets called, the application.cfm
file is run first. All The Time.
You can imagine how horrible the resulting page would look if you ended up
with four headers all nested inside one another.
This is kind of an exaggeration, but I hope it illustrated the point as to
why you never put anything other that application *logic* in an
application.cfm or onrequestend.cfm. It's a gross abuse of the system and
before long, as soon as your sites get any kind of complexity to them, it
will cause many more headaches that it seems to solve.
Not a sermon... Just a ... Well... Ok, maybe it was a sermon.
-Patti
Rick H Kennerly wrote:
> |o| your development in due course. You might not want to put your
> |o| header and
> |o| footer on application.cfm and onrequestend.cfm respectively. Though it
> |o| works, its not meant to put templates or any visual display
> |o| items. It's not
> |o| a standard practice either.
> |o|
>
> Guess I didn't make it clear, or atleast don't understand.
>
> the files header.cfm and footer.cfm are actually called by CFINCLUDE in the
> Application.cfm and OnRequestEnd.cfm. The graphic elements are not actually
> in the Application file. Is still not a good idea? I'd gotten the idea to
> that from a guide I was reading.
>
> Rick
>
>
>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Signup for the Fusion Authority news alert and keep up with the latest news in
ColdFusion and related topics. http://www.fusionauthority.com/signup.cfm