applyLayout
Purpose
Applies the specified layout to either the body, a given template and an arbitrary URL allowing the development of "portlet" style applications and mashups
Examples
<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>
Description
Attributes
name
- The name of the layout to apply
url
- The URL of the content to apply, could be an external URL
template
(optional) - The name of the template to apply
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
Source
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()
}