@mrhaki has a great example.
Let's see how this works with a small sample application. All pages have a header with a logo, search form and main menu. Each page also has a footer with some copyright information. The homepage has a body with five blocks of information, we have product list page with a one column body and finally a product details view with a two column body.
I love the Balsamiq mockups.
A revisited example which improves the previous one by:
using the <g:applyLayout/> in the Groovy Server Pages in the layouts directory instead of in the views. So this way we can use the default method of applying layouts in our views (using for example the <meta/> tag) and keep all <g:applyLayout/>_ tags in the layout pages.
@marsfooh shows two approaches to change Sitemesh layouts depending on a request parameter.
- Use an expression in the meta tag
- Define a Filter ( which will be an interceptor in Grails 3) .