applyLayout
用途
给body指定一个布局应用,并允许使用任意的URL的模板,提供一个 "portlet" 风格的应用程序
示例
<g:applyLayout name="myLayout" template="displaybook" collection="${books}" />
or<g:applyLayout name="myLayout" url="http://www.google.com" />
or<g:applyLayout name="myLayout">
The content to apply a layout to
</g:applyLayout>
描述
属性
name
- 使用布局的名称
url
- 要使用应用的URL, 也可以是外部的URL
template
(可选) - 模板的名称
bean
(可选) - 对应模板的bean
model
(可选) - 对应模板的model 作为 java.util.Map
collection
(可选) - 集合的模板对象
来源
Show Source
def applyLayout = { attrs, body ->
if(!groovyPagesTemplateEngine) throw new IllegalStateException("Property [groovyPagesTemplateEngine] must be set!")
def oldPage = getPage()
def contentType = attrs.contentType ? attrs.contentType : "text/html" def content = ""
if(attrs.view || attrs.template) {
content = render(attrs)
}
else if(attrs.url) {
content = new URL(attrs.url).text
}
else {
content = body()
} def parser = getFactory().getPageParser(contentType) def page = parser.parse(content.toCharArray())
attrs.params?.each { k,v->
page.addProperty(k,v)
}
def decoratorMapper = getFactory().getDecoratorMapper() if(decoratorMapper) {
def d = decoratorMapper.getNamedDecorator(request, attrs.name)
if(d && d.page) {
try {
request[PAGE] = page
def t = groovyPagesTemplateEngine.createTemplate(d.getURIPath())
def w = t.make()
w.writeTo(out) } finally {
request[PAGE] = oldPage
}
}
}
} private Factory getFactory() {
return FactoryHolder.getFactory()
}