render
目的 Purpose
Applies an inbuilt or user-defined Groovy template against a model so that templates can be shared and reused使用例 Examples
Example domain class:class Book { String title String author }
<p>${it.title}</p> <p>${it.author}</p>
List
of Book
s or a single Book
. For a List
the template will be repeated for each instance:<g:render template="displaybook" collection="${books}" />
<g:render template="displaybook" bean="${book}" />
<p>${book.title}</p> <p>${author.fullName}</p>
<g:render template="displaybook" model="['book':book,'author':author]" />
<p>${myBook.title}</p> <p>${myBook.author}</p>
<g:render template="displaybook" collection="${books}" var="myBook"/>
詳細 Description
Note that if the value of the template attribute starts with a '/' it will be resolved relative to the views directory. This is useful for sharing templates between views. Without the leading '/' it will be first be resolved relative to the current controller's view directory then, failing that, the top level views directory. In either case the template file must be named with a leading underscore ('_') but referenced in the template attribute without that underscore or the '.gsp' suffix.属性 Attributes
contextPath
(optional) - the context path to use (relative to the application context path). Defaults to "" or path to the plugin for a plugin view or template.template
(required) - The name of the template to applybean
(optional) - The bean to apply the template againstmodel
(optional) - The model to apply the template against as ajava.util.Map
collection
(optional) - A collection of model objects to apply the template tovar
(optional) - The variable name of the bean to be referenced in the templateplugin
(optional) - The plugin to look for the template in