Skip to main content
2Charlie
Inspiring
May 12, 2016
Answered

How to use cfhtmlhead tag?

  • May 12, 2016
  • 1 reply
  • 1479 views

I found this documentation, Adobe ColdFusion 9 * cfhtmlhead , but how do I use it in my page? Where do the <cfhtmlhead text="#sHeader#"> tag go on the page?

Okay, so this is what I have.

<cfsavecontent variable="sHeader">

  <cfoutput>

  <title>#title# | My Company Site Claire</title>

  <meta name="keywords" content="#tags#"  />

  <meta property="og:locale" content="en_US"/>

  <meta property="og:type" content="website"/>

  <meta property="og:title" content="#cfData.data.name#"/>

  <meta property="og:url" content="#canonical#" />

  <meta property="og:site_name" content="My Company website"/>

  <meta name="twitter:site" content="@MySite">

  <meta name="twitter:title" content="#cfData.data.name#">

  <meta name="twitter:creator" content="@MySite">

  <link rel="canonical" href="#canonical#" />

  </cfoutput>

</cfsavecontent>

<cfhtmlhead text="#sHeader#">

Okay, so now that I have the "text" in the cfhtmlhead tag, do I have to do anything else for it to show inside of the header section of the page?

    This topic has been closed for replies.
    Correct answer 2Charlie

    Yes, that could be the problem. If index.cfm is the only script that calls apiCall.cfm then any page that you browse to, other than index.cfm, will not contain the meta data you are expecting.

    Are you perhaps confusing index.cfm with application.cfm?

    Cheers

    Eddie


    I figured it out. CFSaveContent cannot be inside of the cfoutput tag. If I move from line 8 to 20 out of the cfoutput, it works.

    1 reply

    EddieLotter
    Inspiring
    May 12, 2016

    2Charlie wrote:

    do I have to do anything else for it to show inside of the header section of the page?

    No, but why bother? Why not replace <cfcontent> with <head> which is so much clearer.

    Cheers

    Eddie

    2Charlie
    2CharlieAuthor
    Inspiring
    May 12, 2016

    Thanks for the response. Do I need to put what's in the <cfcontent> or <head> at the very top of the document or can I put it anywhere on the page? The thing is, some of the information like title and tags can only be extracted once an API has been called. Thus, I need to save the content in the <cfsavecontent> tag but then I don't know where else on the page to place the <cfhtmlhead> tag.

    EddieLotter
    Inspiring
    May 12, 2016

    You can use <cfContent> and <cfHtmlHead> anywhere in the script (as long as you're not flushing), but using <head> has to be in its correct place within the script.

    In other words, the following two examples will produce equivalent HTML:

    <!doctype html>

    <html lang="en">

    <head>

      <meta charset="utf-8">

    </head>

    <body>

    <!--- API calls here. --->

    <cfsavecontent variable="sHeader">

      <title>My Title</title>

    </cfsavecontent>

    <cfhtmlhead text="#sHeader#">

    </body>

    </html>

    or

    <!doctype html>

    <html lang="en">

    <head>

      <!--- API calls here. --->

      <meta charset="utf-8">

      <title>My Title</title>

    </head>

    <body>

    </body>

    </html>

    Cheers

    Eddie