Setting default layout in Grails application

05 / Apr / 2012 by Uday Pratap Singh 0 comments

Grails uses Sitemesh for adding layout to the views. Layouts are located in layouts folder and to add layouts to the view we generally add any of the following line in head
[java]
<g:applyLayout name="layoutName"/>
or
<meta name="layout" content="layoutName" />
[/java]

But most of the time we have single layout, so why we repeat the same line for adding layout in our gsps. Grails has the solution for this as well.
Grails comes with a config property grails.sitemesh.default.layout which will set the layout of the page if there is no layout tag added to the gsp. We just need to write the following lind in Config.groovy and its all done
[java]
grails.sitemesh.default.layout = ‘layoutName’
[/java]
But the bad part is it doesn’t work with the scaffolded code even if I update the template of my view and remove the meta tag of layout. It would be nice if grails comes with this config property and I just need to update the layout property to change the layout.

Hope it helps
Uday Pratap Singh
uday@intelligrape.com

FOUND THIS USEFUL? SHARE IT

Leave a Reply

Your email address will not be published. Required fields are marked *