Wait for it….
CFHTMLHEAD
“Is that all” I hear you cry? Maybe even a “WTF is CFHTMLHEAD?”..
Well, to quote the documentation:
“Writes text to the head section of a generated HTML page.” Simple eh?
Wait for it….
CFHTMLHEAD
“Is that all” I hear you cry? Maybe even a “WTF is CFHTMLHEAD?”..
Well, to quote the documentation:
“Writes text to the head section of a generated HTML page.” Simple eh?
Use this link to trackback from your own site.
lol - easy pleased
cfhtmlhead is ace though…
My one tip for working with CFHtmlHead is COMMENT COMMENT COMMENT. I had to work on another guy’s project in which CFHtmlHead was being used and it took me about four hours to figure out where the heck code in the HEAD tag was being added! It wasn’t explicitly in the header so, when you think about it, it nearly impossible to debug without actually tracing every single line of code in a given request.
So, it wouldn’t hurt to, in the header files, just put a comments like:
NOTE: CFHtmlHead being used in the following files….
Ben,
I would make certain those “debugging comments” are available only on your development servers or via a debug setting on your live servers.
Awfully dangerous to be giving out filenames for free.
My codebase makes extensive use of cfhtmlhead, but only because the original developers decided they wanted to include the headers and footers of the app in Application.cfm. So now, our ONLY choice when we need to inject javascript on a page by page basis is that tag. I generally use a cfsavecontent tag to store the code into a variable, then cfhtmlhead that var. Makes it much easier to read, and you don’t have to worry about escaping single or double quotes.
One thing to watch out for with cfhtmlhead is that it [appears] to blindly find the first occurrence of any closing </head> tag in the page, prefixing whatever value you pass it immediately before that tag.
If you have any inline js that, say, opens about:blank in a new window then writes html to that window, then more often than not the cfhtmlhead will insert its text in the middle of your js function if you have an occurrence of </head> (solution is simply to concatenate values like ‘</he’ + ‘ad>’).
cfhtmlhead is great for simple one-off type of insertions of text or script blocks but I would consider it a secondary choice for most things (first being ljs oad() functions that are built during page assembly and fire onload() or having dedicated header/leader includes which contain the stuff you require).