How can I easily control the look and feel of my site?

While non-ColdFusion techniques like an effective CSS file are one way to easily control layout across a site, you also want to consider using custom tags, and custom tag "wrappers" as a way to maintain a consistent look and feel across your site. Custom tags "wrappers" are simply custom tags that wrap content. As an example:

<cf_foo>
Stuff here
</cf_foo>

When ColdFusion runs this file, it will execute the custom tag, foo, twice. Once before "Stuff here" and once after. You can programatically determine if foo is being run in the beginning or end of execution. This is done using the builtin thisTag scope and the executionMode value.

<cfif thisTag.executionMode is "start">
Code here to run in the beginning.
<cfelse>
Code here to run at the end.
</cfif>

This technique then is very useful for handling layout. You can easily use a layout custom tag that handles outputting a header and footer using the code above. Then wrap your pages with code like so:

<cf_layout>
This is my page!
</cf_layout>

This entry was based on a suggestion by Mat Evans.

This question was written by Raymond Camden
It was last updated on July 3, 2008.

Categories

Display and Layout

Comments

comments powered by Disqus