ColdFusion Custom Tags As Page Wrappers

Posted November 7, 2006 at 3:04 PM by Ben Nadel

Tags: ColdFusion

As I have said, I have been looking through a lot of code lately for inspiration and I keep seeing this type of thing:

  • <page:wrapper
  • layout="basic"
  • title="I am a demo page">
  •  
  • <!--- Content of page goes here. --->
  •  
  • </page:wrapper>

In this case, the "Wrapper" ColdFusion custom tag is meant to encapsulate the calling of the site header and footer. That makes sense to me. What I am having trouble with is passing in the LAYOUT and the TITLE as a wrapper tag attribute. This just seems wrong to me. I don't think that the page should know about it's own layout or title. Call me crazy, but isn't the main content just another "module" in the returned web page? Thing about a page that has a header, left hand content, main content, right hand content, and a footer. Isn't the main content just another portion of the page? Why does it get to decide what page layout to use? It seems no more appropriate than if the footer determined the page layout.

In fact, it seems quite the opposite: isn't the page layout the ruling force in determining which page modules are included? Now, please don't get me wrong - I am not saying that you should invoke the page layout and then have it, in turn, include the "main" page content - I like including a header and footer on the "main" content template. All I am saying is that I think the page layout and title should be decided upon before the main page content is executed and that the main content should be layout-agnostic. After all, why should it care what layout template it is being used in?

Any thoughts on this?



Reader Comments

Nov 7, 2006 at 7:39 PM // reply »
15 Comments

Ok Ben, you write a lot of good posts, but today you really need to relax a bit and stop talking in such absolutes. There is nothing "wrong" with that technique, and while I don't use it for my mach ii sites, the net effect of a layout template is the same nonetheless....the "content" area of my layout includes the generated content from mach ii.

Should the content be agnostic to the layout? perhaps that is preferable, but it isn't always realistic, and the example you give seems like a perfectly acceptable solution for a large portion of web site/applications. Anyway, I know a good deal of circumstances where that just doesn't happen for various reasons - sometimes it just isn't realistic. Is that wrong? No, because, as I am sure you are well aware, when developing an application, there is what I would love to do and what is realistic.


Nov 7, 2006 at 8:46 PM // reply »
11,241 Comments

Brian,

I agree that I sometimes do rant, but 100% honest, this post was not one of them. This post was meant to be a question more than anything. I do not use custom tag wrappers at all and cannot say one way or another which way is good. This post was meant to be a thought meant for feedback. I appologize if it came across as an absolute.

If there is any "Edge" that comes across is any of my posts, ususally it is only out of frustration that I do not have the answers. This is the frustration of self-realized inadequecy. I like the idea of tag wrappers and I am looking forward to implementing one, but I just want to make sure I have all the info before I do it. Not that this is some huge mission critical thing, I just am very curious about this stuff and 99% of the time I feel that I am only 1% there.

Many appologies.


Nov 7, 2006 at 9:23 PM // reply »
15 Comments

Seriously, there was no offense taken at all...no need for apologies. I just wanted to clarify that there was absolutely nothing wrong with the method that I saw even if you thought you could build something more flexible. However, in my prior position at Hasbro, I used the exact method you describe and was actually the one who recommended we implement it...it was, in fact, far more flexible than the solution that was previously used and worked well with all the existing legacy code. Did that mean that each page was tied to a specific layout implementation? Yes. Did that matter in this case? No...or at least not at the time.


Nov 8, 2006 at 7:23 AM // reply »
11,241 Comments

Brian,

First off, that's cool that you used to work at Hasbro. Secondly, it's good to know that both method work well depending on the context. I think that is part of my mental block with custom tags in general. I use them for page widgets and I have a mixture of tag attributes and global variables (directly referencing the REQUEST / APPLICATION scopes). I already blogged about this as a questionable practice, but I do it anyway, cause it works really well for the situation.

Like I said, I am just trying to get all the information I can. Glad there's no hard feelings.


Nov 8, 2006 at 11:16 PM // reply »
111 Comments

To be fair I get exactly why Ben is trying out "absolutes" on his blog. The more you look at different code, trying to select an approach the more you try to come up with "this is better than that" comments - not to diss an approach, but just to get off of top dead center and move in a direction. The great thing about saying one approach is better than another is that it can provide contrarian feedback you might not have thought of.

If someone posts on why IBOs suck, that is great as (if I have time) I get a chance to think about what they consider to be a weakness and then either improve my approach or (again if I have time) suggest why their "rule" might either be fundamentally wrong (something they didn't consider) or situationally wrong (for my use case x works because y isn't a concern).

I'd say keep up with the absolutes (as long as you understand that about half of the time you'll be absolutely wrong :->).


Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
May 22, 2013 at 7:52 AM
Nested Views, Routing, And Deep Linking With AngularJS
Hi, Just a quick thank you. As it happens, for my own purposes, the pending ui-router work being done in native angular is likely the one I'll adopt, but your exploration, code and documentation of ... read »
May 22, 2013 at 4:43 AM
How Do You Use The ColdFusion CFParam Tag?
'<cfparam>' or 'isDefined()and <cfset>' performs the same task.Is there any difference? ... read »
May 21, 2013 at 7:46 PM
Using Plupload For Drag & Drop File Uploads In ColdFusion
No luck. At least I have uncovered the cause, URLScan 3.1. Here is what I see in the IIS log when a file is over 30mb. 2013-05-21 23:29:05 10.105.45.128 GET /plupload/assets/jquery/jquery-1.8. ... read »
May 21, 2013 at 6:12 PM
Using Plupload For Drag & Drop File Uploads In ColdFusion
Ben, I did not see you after Pete Freitag's Lockdown session at cfObjective but he said that IIS sets file size limits at 30MB by default which just happened to be the threshold for file size when ... read »
May 21, 2013 at 11:51 AM
Ask Ben: Parsing Very Large XML Documents In ColdFusion
Looking at my first ever XML document that I have to parse and put into MS SQL 2000 with CF8. I get it to list the desired Field name, many times over, and have a long list of this field name displa ... read »
May 21, 2013 at 9:25 AM
Turning Off and On Identity Column in SQL Server
you are awesome..i am lucky to get this blog between such a garbage one....Thanks, Prashant ... read »
May 20, 2013 at 4:38 PM
Using A Dynamic Column Name With ValueList() In ColdFusion
@Dana, Your confusion is well founded, since this is a very confusing features. In fact, it ONLY works if you use array notation. Meaning, that this: arrayToList( query[ "columnName" ] ) ... read »
May 20, 2013 at 4:34 PM
Using A Dynamic Column Name With ValueList() In ColdFusion
I was thinking chicken and the egg, I wouldn't have expected it to work in the valuelist going in I guess. Maybe I just need a beer, long day :) ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools