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 »
10,640 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 »
10,640 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
InVision App - Prototyping Made Beautiful With Prototyping Tools Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
Feb 10, 2012 at 7:21 PM
jQuery AJAX Strips Script Tags And Inserts Them After Parent-Most Elements
Update! Instead of $(eval(options.insertAfter)).after(data['insertData']); I now use: var ajaxNode = document.createElement('span'); var parent = $(eval(options.insertAfter))[0].parentNode; ... read »
Feb 10, 2012 at 6:18 PM
jQuery AJAX Strips Script Tags And Inserts Them After Parent-Most Elements
encountered this same, what I consider, jQuery bug last week. I'm building a site in which I load some content via AJAX. This content contains Linkedin share button placeholders which Linkedin API ne ... read »
Feb 10, 2012 at 11:30 AM
Cross-Origin Resource Sharing (CORS) AJAX Requests Between jQuery And Node.js
After you understand the concepts here, this is an awesome cheatsheet for enabling CORS in just about anything http://enable-cors.org/ ... read »
JM
Feb 10, 2012 at 9:10 AM
My Safari Browser SQLite Database Hello World Example
@Amy, Here is a very good tutorial on how to use JOIN: http://www.sqltutorial.org/sqljoin-innerjoin.aspx ... read »
Feb 10, 2012 at 4:42 AM
Building A Twitter-Inspired RESTful API Architecture In ColdFusion
This is great, very useful Ben. I spotted a small typo in the api.cgm listing: <cfthrow type="Unauthroized" /> Cheers Stefan ... read »
Feb 9, 2012 at 10:35 PM
CFDirectory Filtering Uses Pipe Character For Multiple Filters (Thanks Steve Withington)
I was wondering if there would be a filter you could apply so that you got everything but what you included in the filter. As in show me all docs that are not a .pdf. ... read »
Feb 9, 2012 at 10:29 PM
Learning ColdFusion 9: Application-Specific Data Sources
@Ben, No offence, but if people were really wanting advanced features they would be using a platform like ASP.NET MVC. CFML is so structurally compromised as a tag-based scripting language that ... read »
Feb 9, 2012 at 10:03 PM
Subversion - Cleanup Failed To Process The Following Paths
@Leviaguirre, do you still have problems with this? ... read »