Eric Belair
Eric Belair

Reputation: 10682

Why is CFHTMLHEAD not working in ColdFusion 11?

I've tested several pages so far, and it seems that wherever I am attempting to use <CFHTMLHEAD> to add CSS or JavaScript to a CFM page in ColdFusion 11, it will not add it (works fine in CF8).

I read on SO about increasing the "Maximum Output Buffer size" in the Administrator > Server Setttings > Settings from the default valut of 1024KB, but every value I've tried (2048KB, 4096KB, and even the max allowed 999999KB) I get the same result - the content is not included in the <HEAD> tag when the page loads.

Has anyone else run into this and found a solution yet?

Code Sample:

htmlhead.cfm:

<cfif NOT ThisTag.HasEndTag>
    <cfthrow message="Missing end tag for custom tag htmlhead." type="HeadWrap" />
</cfif>

<cfif ThisTag.ExecutionMode is "End">
    <cfhtmlhead text="#ThisTag.GeneratedContent#" />
    <cfset ThisTag.GeneratedContent = "" />
</cfif>

index.cfm:

<cfsilent>
    <!--- 
        Data Retrieval, validation, etc. here
    --->

    <cf_htmlhead>
        <style type="text/css">
            tr.status-RETIRED td {
                color: #800000;
            }

            tr.status-PENDING td {
                color: #008000;
            }
        </style>
        <script type="text/javascript">
        $(function(){
            $(".options-menu").mouseleave(function(e){
                $(this).hide("fast");
            })

            $(".options-menu-link").mouseover(function(){
                $(".options-menu").hide("fast");

                $(".options-menu[data-sku='" + $(this).data("sku") + "']").show("fast");
            }).click(function(e){
                e.preventDefault();
            });
        });
        </script>
    </cf_htmlhead>
</cfsilent>

<!--- 
    Custom Tag layout.cfm contains the DOCTYPE declaration, html, head (loads jquery, jquery-ui, css, etc.), and body tags with a header and footer for each page.
--->
<cf_layout>
    <!--- Page Content Here (a form, a table, some divs, etc.) --->
</cf_layout>

Upvotes: 0

Views: 1235

Answers (1)

Dave Jones
Dave Jones

Reputation: 46

I've found that in CF11 anything added using a cfhtmlhead call that comes before a cfcontent reset="true" does not get added to the resulting document. Does the cf_layout tag you are calling after your cf_htmlhead contain a content reset?

For example,

<!--- This will not be added under CF11. --->
<cfhtmlhead text="<!-- I'm some content that will only be included in CF10 or lower. -->">

<cfcontent reset="true">

<!--- This will be added under CF11 and lower. --->
<cfhtmlhead text="<!-- I'm some content that will be added in CF11 and lower. -->">

... the rest of your view code ...

<!--- This is a sample of the content you will get under CF11 --->
<!doctype html>
<html>
<head>
   <meta charset="UTF-8" />
   <title>Head Testing</title>
      <!-- I'm some content that will be added in CF11 and lower. -->
   </head>
   <body>
      <h1>Page content</h1>
   </body>
</html>

Upvotes: 3

Related Questions