ColdFusion Custom Tags As Page Wrappers

Posted November 7, 2006 at 3:04 PM

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:

 Launch code in new window » Download code as text file »

  • <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?

Download Code Snippet ZIP File

Post Comment  |  Ask Ben  |  Permalink  |  Other Searches  |  Print Page




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 »
6,371 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 »
6,371 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 Comment  |  Ask Ben

Recent Blog Comments
Nov 7, 2009 at 5:53 PM
Ask Ben: Javascript String Replace Method
You can find here an advanced function that prepared with javascript replace function. This can make the first letters of words, sentences, lines and whatever you define automatically: http://www.m ... read »
Andrew Neely
Nov 7, 2009 at 4:56 PM
A Moment That Touched Me - The Fountainhead
Ben, Glad you enjoyed the podcast. Yeah, the Tank Riot guys can get really chatty during the episodes, but that's part of the charm of it for me. They've covered everything from Nichola Tesla to Cha ... read »
Nov 7, 2009 at 4:43 PM
Building A Fixed-Position Bottom Menu Bar (ala FaceBook)
Is it possible to make some more MenĂ¼`s ? ... read »
Jill
Nov 7, 2009 at 11:40 AM
How To Unformat Your Code (Like A Pro)
Derek, I think you might be right - sweet! Thanks for the link :) ... read »
Nov 7, 2009 at 11:25 AM
How To Unformat Your Code (Like A Pro)
I think it would be way easier to just use this http://www.logichammer.com/html-formatter/ He just released v3 and it rocks. ... read »
Jill
Nov 7, 2009 at 7:58 AM
How To Unformat Your Code (Like A Pro)
LMAO - this was pretty funny! I have to admit - I also love to reformat code so I can read it. My boss used to tell me to leave my OCD at home. Now I don't feel so bad after reading everyone else' ... read »
Nov 6, 2009 at 10:10 PM
How To Unformat Your Code (Like A Pro)
The timing of this post is just uncanny. I spent the last 15-20 minutes manually un-formatting my "Ben Nadel" style code within a CFC of mine. I was really digging the readability a few weeks ago, bu ... read »
Roe
Nov 6, 2009 at 5:11 PM
Passing Arrays By Reference In ColdFusion - SWEEET!
ArraySort also reorders the results of these java obj's ... read »