Welcome!

ColdFusion Authors: Yakov Fain, Pat Romanski, Liz McMillan, Maureen O'Gara, Greg Ness

Related Topics: ColdFusion

ColdFusion: Article

Steve Bryant's ColdFusion Blog: HTML in Application.cfm

It is possible that a client might want part of the layout to change based on which page is being displayed

The CF_Talk list recently had a discussion about whether it is acceptable to put HTML in Application.cfm. I thought the topic was a very worthy one, but ended up shedding as much heat as light.

I will do my best to shed some light on the topic.

In the short-run, putting HTML in Application.cfm (or including HTML from Application.cfm) can speed up development. If your project ends up changing over time (as most do), however, this can lead to code that is difficult to maintain.

This approach causes problems when different pages have different layouts. For example, a pop-up page would use a different layout than other pages on a site as might the home page.

A common solution is to use a different directory for pages with a different layout so that you could use a different Application.cfm. This makes it slightly more difficult to make common, site-wide logic available to the pages with alternate layouts. The difficulties are more pronounced for a home page with a different layout. Putting every other page in a different directory is impractical.

You could have Application.cfm decide which layout to use based on the file name instead. For example, index.cfm might have a different layout than other files. This is problematic when you or your client want to make a quick copy to test a change.

For example, you might copy index.cfm to index2.cfm at which point the correct layout is no longer being used. Or, perhaps the client might want an alternate home page. Yes, you can always edit Application.cfm with the new file name, but it is counter-intuitive. People expect a copy of a page to look the same as the original.

In fairness, one advantage to including HTML in Application.cfm is that it makes including one page from another very easy (whether or not that is a good idea is another discussion).

On the flip side, it is possible that a client might want part of the layout to change based on which page is being displayed. If you were including the layout code from the page, you could set a variable above the call to the layout to indicate this and perhaps to make some data available for that purpose. If you were including your layout from Application.cfm, that is one more file name check that you have to add to Application.cfm.

These extra bits of code in Application.cfm may not seem like a big deal, but over time they add up to confusing code that is difficult to maintain.

Good luck!

More Stories By Steve Bryant

Steve Bryant is the founder and CEO of Bryant Web Consulting LLC (www.bryantwebconsulting.com) and teaches ColdFusion at Breakaway Interactive (www.breakawayinteractive.com). He got his BA in philosophy at Oklahoma State University. Steve, one of the top ColdFusion developers in the country, still has no idea how that led to a career in Web development. Steve blogs at steve.coldfusionjournal.com as one of CFDJ's published bloggers.

Comments (1) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
ColdFusion Developer's Journal News Desk 01/07/06 03:36:31 PM EST

On the flip side, it is possible that a client might want part of the layout to change based on which page is being displayed. If you were including the layout code from the page, you could set a variable above the call to the layout to indicate this and perhaps to make some data available for that purpose. If you were including your layout from Application.cfm, that is one more file name check that you have to add to Application.cfm.