Cool Tags You Sometimes Forget About

I'm guilty of this - I'm sure we all are - but I often get comfortable with a handfull of tags and tend to forget that there are so many tags in CF that make our lives easier. Recently I was reminded of <cfhtmlhead>.

The docs explain this tag like this:

Writes text to the head section of a generated HTML page.

Usage

Use this tag for embedding JavaScript code, or putting other HTML tags, such as meta, link, title, or base in an HTML page header.

If you use this tag after the cfflush tag on a page, an error is thrown.

Pretty simple, right? There is one attribute: text. Just pass in the code you want added to the head. Here's a quick example:

<cfsavecontent variable="dynamicTitle">
   <title>Dynamic Page Title As Of #now()#</title>
</cfsavecontent>
<cfhtmlhead text="#dynamicTitle#">

The dynamic page title is appropriately written to the html head section. Like the docs say this is handy for JS, meta (keywords), stylesheet links, etc. You can also write the code directly in the text attribute instead of saving as a variable first but I think it's a little cleaner to use the savecontent.

<cfhtmlhead text="<title>Dynamic Page Title As Of #now()#</title>">

What tags have you "redisovered" lately?



Comments
It took me about three days to track down CFHtmlHead-related content that was inexplicably showing up in the header of site I inherited.

For those of you who use CFHtmlHead... PLEASE PLEASE PLEASE document the use, otherwise it makes you think the code is bananas.
# Posted By Ben Nadel | 3/16/07 11:14 AM
Ouch - but good point.
# Posted By todd sharp | 3/16/07 11:27 AM
I use this tag to load my js libraries.

I tie the loading of the library with the content that uses it so that only libraries that are needed get loaded on any given page.
# Posted By Paul Roe | 3/16/07 11:39 AM
This tag is another one of those "so cf" bits: takes an otherwise difficult problem and just solves it. I use it to load js libraries as follows: i have a request scoped array in which i register the js libs i'm going to need as i composing the page. Once that's done and i'm drawing the output, adding layout, etc, i loop through this array and extract unique references, and then use the tag to add the required js files. That way, i can use a component (typically a widget) any number of times, but the related js code is only included once.
# Posted By tanguyr | 3/16/07 12:52 PM
I rediscovered CFHTMLHEAD about a year ago when I was making a big push to make the output of my company's CMS meet some level of standard. We had JS and even CSS embededded within distributed content that was ultimately output into the body of the rendered page. It was ugly.

CFSAVECONTENT+CFHTMLHEAD took care of that.
# Posted By Rob Wilkerson | 3/16/07 1:54 PM
Thats funny. Last week I ran into this tag again after forgetting about it for awhile.

same thing, I had come across script code in the body that was annoying me. Good call on re-documenting that though, I apparently have a todo: item when I get back to my desk later :o
# Posted By DK | 3/20/07 12:00 PM
Thanks for this post Todd, I came back to it a few days ago and have been updating some code. I used to just load my JS files on the included pages they are used on. Now I've used this tag to actually put them where they belong. I feel so proper!

Thanks to Ben for his comment as well, I hadn't thought about that. I just added some HTML comment tags to the code stating where the header information is coming from. Is that what you meant by documentation?

Ryan
# Posted By Ryan Everhart | 4/13/07 8:59 AM
@Ryan,

Yeah, that sounds good. Otherwise, if you don't know the tag is being used, it looks like HTML markup is coming out of no where!
# Posted By Ben Nadel | 4/13/07 9:25 AM
Thanks Ben!!!

It's so cool to have people like Ben and Todd around! This community rocks!

Ryan
# Posted By Ryan Everhart | 4/13/07 9:34 AM
Deleted that last comment. Looked like a cheap human spam comment to me.
# Posted By todd sharp | 8/3/07 11:53 AM
This is indeed a great tag and has helped me with my CMS application as well. The one thing I wish you could control manually is whether the value gets appended to the header or prepended. Sometimes all I want to modify is the page title which I think is supposed to be at the top of the header.
# Posted By David Levin | 10/1/07 5:16 PM

Calendar

Sun Mon Tue Wed Thu Fri Sat
      1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30       

Subscribe

Enter your email address to subscribe to this blog.

Tags

actionscript ajax blogging cfsnippets coldfusion flash forms flex funny stuff misc model-glue off topic personal project learn slidesix sql

Recent Comments

Editing A Query In A SQL Server DTS Package
JD said: Thanks for your post. Never unlike Microsoft to hide stuff in the hardest part time find. [More]

Mashing Spry Effects With CF8 Ajax Goodness
Mark Pitts said: I have had moderate success implementing Spry Accordian. Sadly the part that does is not working wil... [More]

Chinese Birth Calendar Accuracy Test
Toni Lehman said: This calendar was accurate for both my daughters and 4 grandchildren. I tried it for 11 of my other ... [More]

Virtual Memory - Am I The Last To Know?
Larry Miller said: The authors friend was right. Windows virtual memory system was designed by experts and they fully u... [More]

Using A PlayStation 2 HDD In Your PC
Alacres said: Thanks so much for the guide man! I did have a more specific question though, since I didn't see it ... [More]

RSS


coldfusionbloggers

FullAsAGoog MXNA

Consumed By Feed-Squirrel.com