4

As the title says... I'm using grails to build a webpage and I know grails uses sitemesh to mesh GSPs. I have done some googling and I found 2 ways to "tile" gsps (the g:applyLayout and g:render template tags). Both seem to do the job of "tiling" gsps so my question is, what's the difference?

EDIT:

For example, I'll use a tiles definition.

<tiles-definitions>
  <definition name="myapp.homepage" template="/layouts/classic.jsp">
    <put-attribute name="title" value="Tiles tutorial homepage" />
    <put-attribute name="header" value="/tiles/banner.jsp" />
    <put-attribute name="menu" value="/tiles/common_menu.jsp" />
    <put-attribute name="body" value="/tiles/home_body.jsp" />
    <put-attribute name="footer" value="/tiles/credits.jsp" />
  </definition>
</tiles-definitions>

and you use tiles:addAttribute to "inject" a page into the jsp.

It was to my understanding that any gsp that isn't a page you would navigate to (so the "tiles") should be placed into layouts in grails. So i guess the issue i'm concirned with is 1. How do you do this using grails/sitemesh most effectivly, and 2. If a layout is not what I am led to believe it is, then what is it?

Matt Westlake
  • 3,499
  • 7
  • 39
  • 80

2 Answers2

2

I think the major difference between applyLayout and render is that applyLayout is more used to apply an overall styling/positioning to a particular page or section of a page. e.g. using

<g:applyLayout name="myLayout" url="http://www.google.com" />

will apply your "myLayout" to the google.com url page and place it where you include that tag.

My understanding of when the render tag should be used for pretty much everything else. To render (create the html) for a given template gsp section. It is especially handy to be able to render a particular section of html (aka template) over and over again for each item within a collection with this syntax

<g:render template="displaybook" collection="${books}" /> 

However you could use something like

<g:applyLayout name="myLayout" template="displaybook" params="[books: books]" />

when you wanted to apply a different layout of "myLayout" to the template "displaybook".

Hope that helps

Tom

dawogfather
  • 604
  • 5
  • 10
1

Here is an excellent example that answers your question on how to most effectively use grails/sitemesh.

Joshua Moore
  • 24,706
  • 6
  • 50
  • 73