Cool Tags You Sometimes Forget About
Posted By : todd sharp Posted At : March 16, 2007 9:25 AM Posted In: ColdFusion
11
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:
<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.
What tags have you "redisovered" lately?



For those of you who use CFHtmlHead... PLEASE PLEASE PLEASE document the use, otherwise it makes you think the code is bananas.
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.
CFSAVECONTENT+CFHTMLHEAD took care of that.
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
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
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!
It's so cool to have people like Ben and Todd around! This community rocks!
Ryan