Question

I've been battling various resource inclusion issues in my migration from Grails 1.3.7 from Grails 2.0, probably not understanding a few things to begin with.

Firstly, what does

<g:javascript library="application" />

do? (this was in the default main.gsp provided in Grails 1.3.7).

Secondly, for including jquery across my application, can I just do

<r:require module='jquery' />
<r:layoutResources />

in the top of my main sitemesh page that does the

 <g:layoutHead /> 
    ...
 <g:layoutBody />

and "be done with it", using the

<r:layoutResources />

a second time after the

 <g:layoutBody />

Thanks

Was it helpful?

Solution

Yes I struggled a little with this at first too.

So firstly the <g:javascript library="application" /> refers to a module defined in a config/*.Resources.groovy file (default is config/ApplicationResources.groovy), inside that you have named modules, eg:

modules = {
    application {
          resource url: 'js/jquery/jquery-ui-1.8.15.custom.min.js', disposition: 'head'
  }
}

Secondly by example a Grails2 main.gsp (cutdown a lot here):

 <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title><g:layoutTitle default="Grails"/></title>
    <link rel="stylesheet" href="${resource(dir: 'css', file: 'main.css')}" type="text/css">
    <link rel="stylesheet" href="${resource(dir: 'css', file: 'mobile.css')}" type="text/css">

    <link rel="stylesheet" href="${resource(dir: 'css/redmond', file: 'jquery-ui-1.8.15.custom.css')}" type="text/css">

    <g:layoutHead/>
    <g:javascript library="jquery"/>

    <r:require module="application"/>
    <r:layoutResources/>

</head>

<body>
    <g:layoutBody/>
    <r:layoutResources/>
</body>
</html>

Hope that sets you in the right direction

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top