Click to Play

Are You Ready For ChaCha?
Today ChaCha launched a powerful new mobile initiative. The human-powered search engine’s service is called textChaCha. WebProNews Reporter Abby...

Web News

Canada an ‘important first step'
Prior to Bill Gates' keynote address, technology reporter Matt Hartley sat down with the man heading up Microsoft's entertainment and devices division, which oversees the development of the Zune and the...

Elysium Internet Closes the Acquisition of Canada...
Elysium Internet, Inc. a profitable online media Company and wholly owned subsidiary of FTS Group, Inc. (OTCBB: FLIP), today announced that it has completed its previously announced acquisition of Dice Ventures, Inc. Based in Ontario, Canada, Dice Ventures...

Microsoft: Zune to be available in Canada
The Zune, Microsoft Corp.'s answer to Apple Corp.'s hugely successful IPod, will finally be available in Canada, according to an announcement made Sunday night at the Consumer Electronic Show in Las Vegas.

Business Wire Expands into Canada
Business Wire today announced its entry into the Canadian market with the opening of a full-service office in Toronto's financial district. Business Wire's North American expansion will provide Canadian clients with direct access to the industry's largest and most...

Tech law issues to watch in 2008
Predicting the future of Canadian technology law is challenging at the best of times, but with upcoming national elections in the United States and possibly Canada, prognostications for the next 12 months...

Sign Up For adCenter - Get $50 In Free* Clicks.
01.07.08


Get Fancy With A Layout Custom Tag

By Raymond Camden

John asks: Somewhere about a year ago, I found an article on using a layout.cfm page "custom tag" to layout the template for the site.

I include a header, menu and footer. I wrap this around all my pages and volia we have a fairly robust template engine. Only now with all the power of the cfc and a huge whole in my plan, I need a new way to do this layout. I need to be able to create different layouts in the content area, but make them reusable through out the site.

With the simple cfcase value="start" and end option I do not have a way to specify the or dynamically call a different layout page without having to write an entire new layout page with that code in there. If that is the best way I can do that but, there has to be a way to make it and I can not wrap my brain around that process.


So normally I don't worry too much about completely different templates. Most sites I've worked on will use one main layout with perhaps just a few variations. The inner content may move from two columns to one column perhaps. To handle cases like that, I simply add new attributes to my custom tag to let me specify which to use, and I try to gauge which layout is used most often and make that the default.

But how would you handle a case where the layout you want is really varied? As always, there are a few things to consider. One simple way is to just use multiple custom tags. So you may have a productlayout.cfm and a reviewlayout.cfm file. This works ok if your file has a hard coded template. I.e., if you always know foo.cfm is a product page, you wrap it with productlayout.cfm. But again - that's hard coded and won't always be appropriate, especially if you want the layout to be chosen by a non-technical user who doesn't want to edit code.

Another possible way of doing this is demonstrated in Galleon. For that project I created a layout custom tag that takes a template attribute. The code for this tag is here:

Sign Up For adCenter - Get $50 In Free* Clicks.

<!--- Because "template" is a reserved attribute for cfmodule, we allow templatename as well. --->
<cfif isDefined("attributes.templatename")>
  <cfset attributes.template = attributes.templatename>
</cfif>
<cfparam name="attributes.template">
<cfparam name="attributes.title" default="">

<cfset base = attributes.template>

<cfif thisTag.executionMode is "start">
   <cfset myFile = base & "_header.cfm">
<cfelse>
   <cfset myFile = base & "_footer.cfm">
</cfif>

<cfinclude template="../pagetemplates/#myFile#">


This layout tag takes a templatename or template attribute (I use both since template is reserved in cfmodule). This points to the base file name inside a pagetemplates folder. So if I request templatename="main", the code will either load main_header.cfm or main_footer.cfm based on the execution mode. This lets me do stuff like this:

<cf_layout template="main">
...
</cf_layout>


Or...

<cf_layout template="#session.mylayout#">
...
</cf_layout>


Again - this is just one example of how it could be done.

Comments

About the Author:
Raymond Camden, ray@camdenfamily.com
http://ray.camdenfamily.com

Raymond Camden is Vice President of Technology for roundpeg, Inc. A long time ColdFusion user, Raymond has worked on numerous ColdFusion books and is the creator of many of the most popular ColdFusion community web sites. He is an Adobe Community Expert, user group manager, and the proud father of three little bundles of joy.

About DevWebProCanada
DevWebProCanada is for professional developers ... those who build and manage applications and sophisticated websites. DevWebProCanada delivers via news and expert advice New Strategies In Development.

DevWebProCanada is brought to you by:

SecurityConfig.com NetworkingFiles.com
NetworkNewz.com WebProASP.com
DatabaseProNews.com SQLProNews.com
ITcertificationNews.com SysAdminNews.com
LinuxProNews.com WirelessProNews.com
CProgrammingTrends.com ITmanagementNews.com


-- DevWebProCA is an iEntry, Inc. publication --
iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509
2008 iEntry, Inc.  All Rights Reserved  Privacy Policy  Legal 


archives | advertising info | news headlines | free newsletters | comments/feedback | submit article


Delivering IT Solutions DevWebProCanada News Archives About Us Feedback DevWebProCanada Home Page About Article Archive News Downloads WebProWorld Forums Jayde iEntry Advertise Contact