Tuesday, December 28, 2010

Grails and application.gsp layout - revisited

Hi there folks!

While I'm developing applications in Grails I always like to have good names for things I create. Controllers, domain objects, views... The only thing I couldn't find a good name for until now was application layout.

As you can imagine the names application.gsp or main.gsp seem like a perfect match for application-wide layouts. The problem with main.gsp is that it's already taken by the scaffolding mechanism and it's very unlikely that the whole application will be based on scaffolded views. The problem with application.gsp however is much more severe. Once you create this guy it'll apply to everything even if there's no layout specified. This also applies not only to views but to static resources as well! So before you go ahead and create the application.gsp file be prepared to what's coming on to you.

But (as usual with Grails) there's hope :) You can rename the global catch-all name of the layout to use for everything in the conf/Config.groovy file:
grails.sitemesh.default.layout = "none"

This way I've specified that the layout named none.gsp will be used as the catch-all instead of application.gsp and so I can use the latter one for my evil purposes :)

I hope this will save someone the headache I've had trying to figure this out, especially with the selenium plugin or partial-renderings from actions (like the ones used in Ajah) that when married with the original application.gsp looks just wrong all along.

2 comments:

Alexandre Masselot said...

looks like a late answer, but I was running into the same problem.

I let the application.gsp unchanged, but want for one gsp (a jasmine test, not the application.gsp to be applied).

This was done with
<meta name="layout" content="none" />

BTW, <g:applyLayout name="none"> was not doing the same results...

Alex

----

<html>
<head>
<meta name="layout" content="none" />

<title>msms aligner - js test"</title>
<r:require modules="js_tests" />
<r:layoutResources />
</head>
<body>
pouet
<r:layoutResources />
</body>
</html>

Alexandre Masselot said...

looks like a late answer, but I was running into the same problem.

I let the application.gsp unchanged, but want for one gsp (a jasmine test, not the application.gsp to be applied).

This was done with
<meta name="layout" content="none" />

BTW, <g:applyLayout name="none"> was not doing the same results...

Alex

----

<html>
<head>
<meta name="layout" content="none" />

<title>msms aligner - js test"</title>
<r:require modules="js_tests" />
<r:layoutResources />
</head>
<body>
pouet
<r:layoutResources />
</body>
</html>