jqueryasp.net-mvccoldfusioncoldfusion-9model-glue

How do I put Javascript in the <head> element of a Coldfusion Model Glue page?


I have a Model Glue CFM page index.cfm with some JS code that I'd like to execute:

<script type="text/javascript">
    $(function() {
        $('#text').height(300);
    });
</script>

<p id="text">This is some text</p>

This is being inserted into a CFM template that looks like this:

<html>
    <head>
        <script type="text/javascript" src="js/jquery.js"></script>
    </head>

    <body>
        <cfoutput>#viewCollection.getView("body")#</cfoutput>
    </body>
</html>

And the relevant part in ModelGlue.xml:

<event-handler name="page.index">
    <views>
        <include name="body" template="pages/index.cfm"/>
        <include name="main" template="templates/main.cfm"/>
    </views>
</event-handler>

Unfortunately, this will stick the Javascript portion directly into the body. Is there a way to put it in the <head> tag without having to create a separate CFM file, similar to how the ASP.NET MVC 3 Razor @section tag works?


Solution

  • You can use <cfhtmlhead>

    For more details, see the docs here.