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




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,572 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,572 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 22, 2010 at 3:08 AM
Ask Ben: Selecting XML Attributes Given Other XML Attributes
Thanks for the response. I finally discovered that I was getting this error because I had cfsetting enablecfoutputonly="yes" in Application.cfc, and was neither setting it to false elsewhere nor brac ... read »
Mar 21, 2010 at 8:57 PM
The Bourne Ultimatum Starring Matt Damon And Julia Stiles
late to the party, but my observation is this: rewatch carefully for the platonic nature of the relationship between nicki and jason. she never flirts with him. he never comes on to her. they alway ... read »
Mar 21, 2010 at 7:40 PM
Is Simulating User-Input Events With jQuery Ever A Good Idea?
A couple of things. One you embed the initial state of of more-info in the CSS. IMHO, that behavior should be in jQuery: moreInfo.hide(); It shows that the behavior your toggling and closing is mor ... read »
Mar 21, 2010 at 3:59 PM
Exploring ColdFusion Component Runtime Class Properties And Serialization
@Elliott, according to Ben's experiment, serializeJSON() doesn't access the private data by default - it doesn't even access the getHair() method - so trying to clone a Girl.cfc via serializeJSON/des ... read »
Mar 21, 2010 at 3:49 PM
Ask Ben: Javascript String Replace Method
I'm confused a bit by what you are asking, but if had this sentence: The color, red, is in the style statement; style: red;. and wanted to remove all or change all of the commas, colons, and semi-c ... read »
Mar 21, 2010 at 3:13 PM
Ask Ben: Javascript String Replace Method
I am trying to make a java program to count the number of times that these punctuation marks occur in a body of text: , : ; . ! - ' " ? / \ I am using this piece to ferret out the commas: numcommas ... read »
Mar 21, 2010 at 11:13 AM
A New Wrist Pain
@chiropractor suwanee, Spoken like someone trying to sell something. Other than for minor, temporary relief from some back pain, chiropractic treatment is nothing but placebo effect and quackery. ... read »
Mar 21, 2010 at 6:32 AM
ColdFusion CFPOP - My First Look
Apologies... The field name in the db for C. is "BounceCode" It stores the code / message which is returned in the email. Sorry for the confusion. ... read »