|
Viewing By Entry / Main
9 Oct. 2005
Here is another way to create website headers and footers. This example website uses ColdFusion custom tags to create very flexible website headers and footers. Using custom tags instead of includes allows you to be able to modify the header and footer with custom tag attributes.
Having headers and footer as custom tags means you could have a basic coldfusion page that is as simple as this: <cf_header title="Demo" css="css/demo.css"> ...content here... <cf_footer>
Custom tags allow attributes to be defined. You can name an attribute "title", then inside the custom tag refer to that as #attributes.title#. For example say you want to have a sitewide header but you need to be able to change the title for each page: <cf_header title="your page title here"> Inside the custom tag the header would contain the html <head> element and the title attribute would be added the title element: <title>#attributes.title#</title>
Adding a title is a fairly simple example. Say you want to do something a bit more complicated like have the header include two additional style sheets, that can be as simple as this: <cf_header title="your page title here" css="css/style1.css,css/style2.css"> In the above code the custom tag header would loop through the list of styles and add them to the html document. See the downloadable example for the code for this.
But what if you want to have menus and/or links in your header that need to be changed. With a custom tag you can send menu items and links into the custom tag by sending an array or structure of menu items in as an attribute. The example website has both a main and side menu done in this way.
The demo example has more functionality: add title, modify header menu, modify a side menu, hide a menu, add meta tags/info, add inline CSS, and add into the body tag.
Comments
For more info on custom tags check out Ray Camden's presentation from CFUnited http://ray.camdenfamily.com/index.cfm/2005/7/1/CFUNITED05-Presentations
|