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?
You can use <cfhtmlhead>
For more details, see the docs here.
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.
精彩评论