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  |  Other Searches  |  Print Page



Learning ColdFusion 9 - ColdFusion 9 tutorials, samples, examples, demos

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 »
7,538 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 »
7,538 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
Mar 17, 2010 at 11:36 PM
Learning ColdFusion 8: CFImage Part I - Reading And Writing Images
@Ben, It is. But I have tested again and sleep() seem to be keeping windows hanging. As a result, multiple people were having issues uploading and removing images when they are trying to do the imag ... read »
Mar 17, 2010 at 11:22 PM
Google Maps Not Working in Internet Explorer (IE)
@James The page has a problem in IE7, because line 112 has a comma at the end. Line 112 is the first problem, there are many more with the same. Ralph ... read »
Mar 17, 2010 at 8:39 PM
Looping Over ColdFusion JSON Queries In jQuery
Thanks Ben - this is just what I needed - just getting up to speed with jQuery - and your posts are accelerating that process substantially :) ... read »
Mar 17, 2010 at 7:50 PM
ColdFusion ArraySplice() Method As An Example Of A Dynamic Method Signature
Java is awesome and I love seeing new twists on it. @Ben - I totally agree with you. ... read »
Mar 17, 2010 at 4:13 PM
Testing For NULL Values In A ColdFusion Query Result Set
To get around the empty strings in an UPDATE statement I pretended the variable was a string by enclosing it in single quotes, CAST it to an integer, let it convert empty strings to zeroes, and used ... read »
Mar 17, 2010 at 4:12 PM
Ask Ben: Environment-Based Application.cfc Settings
Ben, those are valid comments. I posted some code that shows how to "worryfree ;o)" copy code and let the Application.cfc sort it out. http://boncode.blogspot.com/2010/03/cf-dynamically-changing-ap ... read »
Mar 17, 2010 at 3:32 PM
Using Appropriate Status Codes With Each API Response
@Marc, For our project it isn't really a requirement, since most (if not all) of our resources are private and related to the logged in user. Anyway, IIRC google does execute javascript before inde ... read »
Mar 17, 2010 at 3:24 PM
Finally Finished Ayn Rand's Atlas Shrugged Audio Book
Objectivism is a form of positivism, and Quantum Mechanics does not fit positivism. One of the postulates of Quantum Mechanics is the impossibility of separating the object of measurement from the me ... read »