1

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?

tereško
  • 58,060
  • 25
  • 98
  • 150
Daniel T.
  • 37,212
  • 36
  • 139
  • 206
  • 1
    Why do you say "unfortunately" for having scripts in the body? [Steve Souders recommends](http://www.stevesouders.com/blog/2009/05/06/positioning-inline-scripts/) putting scripts at the bottom of the body for performance. – steveax Aug 27 '11 at 22:24
  • Because I can't get the script to go where I need it to. Regardless, the same issue applies: how would you stick all your scripts at the bottom of the body? – Daniel T. Aug 28 '11 at 18:49

2 Answers2

6

You can use <cfhtmlhead>

For more details, see the docs here.

Leigh
  • 28,765
  • 10
  • 55
  • 103
Adam Cameron
  • 29,677
  • 4
  • 37
  • 78
0

You can put JavaScript code in head section of Master.Layout.cfm. you can also put on body section in page from where you are calling JavaScript function.