Header and Footers

A few years ago, I was working on my first non-Fusebox site (by client requirement). I handled layouts (with some modification) by calling the requested file from Application.cfm and then outputting the results in the site layout.

I created a file for decisions about which files should get which layout and I made some exceptions for some pop-up pages.

This seemed to work well, overall. I had a centralized layout file (similar to what I would have had in Fusebox 3). I could make universal changes to the layout in one place. I was able to integrate it with a Fusebox 2 shopping cart that we had chosen for the site.

I recently added some new functionality. Due to time constraints, I subcontracted out the work. I got back an AJAX tool to be used in the site administration. I tested it out and it worked as specified. I copied it into the site and tried it out. It looked right, but the AJAX would never return any results.

The reason, of course, is that the AJAX results were being returned with the layout applied to them. OK. No problem. I went in to the configuration page and made another exception for the AJAX data results. Of course, because I had written the site so long ago it took me a while to figure out the problem.

The site uses a slightly different layout for the home page than for the other pages. So, I create a copy of the home page to test changes. Each time, I have to remember to make an exception for the home page so that it gets the home page layout instead of the default one.

None of these issues are major, but they are still problems.

The problems all stem from a very basic issue: The decision of which layout to use on a page is being made outside of the page itself. If the page made th decision of which layout to apply then it would keep the layout when I copied the home page. If the page made the decision of which layout to use, then the AJAX data pages would have worked, never having had any layout applied to them.

This seems like a lot of work, but it doesn't have to be. If you use cfinclude for headers and footers, you just need to do the include from within your page rather than from Application.cfm and OnRequestEnd.cfm (or Application.cfc).

Personally, I find layout components to be the easiest approach for handling layout issues, but cfinclude is one of several other viable options. The main point here is that a page should make its own decision about which layout (if any) it should use.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.