开发者

How to include css and javascript to main template head section using the grails web framework

开发者 https://www.devze.com 2023-03-05 07:19 出处:网络
I have been using the grails UI performance plugin which handles this with the p:dependantJavascript taglibs.

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 javascr开发者_C百科ipt doSomething() to the head section of the page whenever this template is loaded. Is ther any grails magic to do this?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消