This page last changed on Feb 17, 2006 by graeme.rocher@gmail.com.
Tag - render
Description
Applys an inbuilt or user defined Groovy template against a model so that templates can be re-used for lists or instance or a single instance
Parameters
- template (required) - The name of the template to apply if not specified the tag attempts to pick the most appropriate template for the value type (a calender template for a java.util.Date for example)
- bean (optional) - The bean to apply the template against
- model (optional) - The model to apply the template against as a java.util.Map
- collection (optional) - A collection of model objects to apply the template to
Examples
Example domain class:
class Book {
@Property String title
@Property String author
}
Example template:
<p><%= it.title %></p>
<p><%= it.author %></p>
This template can now be re-used whether you have a list of books or a single book. For a list the template will be repeated for each instance:
<g:render template="displaybook" collection="${books}" />
or
<g:render template="displaybook" bean="${book}" />
or you could create a template that handles a certain type of model. For example the template below:
<p><%= book.title %></p>
<p><%= author.fullName %></p>
Could be used with the model as below. The disadvantage of this technique however is that the template is less re-usable
<g:render template="displaybook" model="['book':book,'author':author]" />
|