templatesgrailsgroovygspsitemesh

Are there any good tutorials for using sitemesh in a grails application?


I'm a pretty experienced Grails developer, but most of my experience has been with using grails for serving up JSON/XML to a flex app and some relatively simple HTML websites.

I've been diving deeper into using the sitemesh integration in grails and I'm struggling a little to find best practices for some more complex configurations, and I'm curious if there are any good tutorials or examples out there. The original Sitemesh website isn't that useful as the tags it talks about aren't directly exposed in grails.

A google search is mostly showing old mailing list posts and some vanilla sitemesh stuff which is helping me to move a little further along, but it's a lot of trial and error.

I fully understand how the basic g:layoutTitle, g:layoutHead, and g:layoutBody tags work. Those are easy and well documented.

The kinds of things that I'd like to see examples for:


Solution

  • Well, I can answer a bit:

    Your first and third questions are related, as you can't chain layouts using the meta tag.

    Your final page should have a meta tag as you suggest, but if you want to layer a layout on top of another layout, you put a g:applyLayout tag at the top of the child layout, pointing at the parent.

    In your edit.gsp, you'd have:

    <meta name="layout" content="editTemplate" />
    

    and in editTemplate.gsp, you'd have:

    <g:applyLayout name="baseTemplate" >
    <!-- the html for the editTemplate -->
    </g:applyLayout>
    

    so edit.gsp would use editTemplate.gsp, which would use baseTemplate.gsp as a base layout. You can chain those as needed.

    I haven't used g:pageProperty at all, so I can't throw you better examples there, sorry.