Reputation: 9304
I have been using the grails UI performance plugin which handles this with the p:dependantJavascript taglibs.
So say im working on a template _someTemplate.gsp
and this template only has the following content:
<div onclick="doSomething()">someContent</div>
now i would like to add the javascript doSomething()
to the head section of the page whenever this template is loaded. Is ther any grails magic to do this?
Upvotes: 0
Views: 4603
Reputation: 10848
You can put javascript tag in the template, like:
<g:javascript src="file.js"/>
UPDATE: The general way to include any javascript & CSS file into the head of a layout is to create a full template:
<html>
<head>
<title><g:layoutTitle default="An example decorator" /></title>
<!-- javascript & css go here, just like normal gsp/html page -->
<g:layoutHead /> <!-- for the specific page -->
</head>
<body>
<g:layoutBody /> <!-- render the specific page body -->
<div onclick="doSomething()">someContent</div>
</body>
</html>
More detailed instructions can be found here.
Upvotes: 3