(Re-) Introducing Layout Components

I have been using the same approach for site layout code for about five years. I have written about it a little bit in the past, but I decided (finally) that it made sense to package it up as a download and write some real documentation around it.

If you are already using an MVC framework on a project then it probably has a solution for layouts backed-in, if not then I would recommend taking a good look at Layout Components. They make layouts easy without introducing any of the challenges that usually come with layout solutions.

Notably, the layout code can all be in one file and you don't have any restrictions on tags that can be used on your pages (CFFLUSH, for example is not restricted). More import (at least to me) is that you can put HTML in the HEAD of the document without resorting to anything ugly like CFHTMLHEAD.

Here is an example of how to output a page (with a custom .css file):

<cf_layout title="My Page">
   <link rel="stylesheet" href="mypage.css" type="text/css" />

Some content here...


So, some of the benefits of Layout Components are:

  • Make edits to the layout in one place
  • Easily switch layouts (per page, section, etc.)
  • Switch to non-HTML formats (PDF, Word, etc.)
  • Use any ColdFusion tags (like cfflush)
  • Do without mappings and relative paths
  • Add HTML to the HEAD
  • See all of the layout in one file
  • Avoid passing all page calls through one file (like index.cfm)

Layout Components are open source and free for any use.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
I played around with the cf_layout tag a little.
It had its moments.
# Posted By Phillip Senn | 2/23/10 10:25 PM

I forgot about CFMZenGarden. That is a really great resource!

As it happens, the cf_layout custom tag doesn't actually have anything to do with cflayout. I can see that the name could be confusing, but it still seemed like the best name for the custom tag.

Layout Components could be used without that tag as well.
# Posted By Steve Bryant | 2/24/10 8:30 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.