Showing posts with label sitemesh. Show all posts
Showing posts with label sitemesh. Show all posts

Thursday, 7 January 2010

Sitemesh layout applied to AJAX response (gotcha)

Grails supports multiple ways to specify a sitemesh layout for your responses. One way I wasn't familiar with is by convention, i.e. if you have a controller 'BookController' and a layout in /views/layouts called book.gsp all the actions in BookController will be rendered with the book layout by default - even if you do render("some text") or render(template: "/sometemplate").

So if you're wondering why all your AJAX responses are getting wrapped up in a sitemesh template this could be the reason. You can stop this by changing the content type to text/plain or by renaming the layout and specifying it explicitly in your gsps using <meta name="layout" content="layoutname"/>.

Monday, 19 May 2008

Dynamic layouts in sitemesh

If you need to add sections into your sitemesh template you can use the <content/> tag.
For example, in main.gsp you might have something like this:

<body>
<div class="nav">
<span class="menuButton"><a href="http://www.blogger.com/" class="home">Home</a></span>
<g:pageproperty name="page.extraNav"/>
</div>
<g:layoutbody/>
</body>

Then you can add extra buttons to the nav bar in your pages by adding:

<content tag="extraNav">
<span class="menuButton"><a href="page/create" class="create">New Page</a></span>
</content>