1.view 中内置 grailsApplication 对象,可以用grailsApplication 后取config对象
<html>
<body>
${grailsApplication.config}
</body>
</html>
2.使用 tmpl 命名空间 渲染模板
<tmpl:bookTemplate book="${myBook}" />
3.使用 pageProperty 获取被装饰页属性
被装饰页例子:
<html>
<head>
<meta name="layout" content="myLayout" />
<script src="myscript.js" />
</head>
<body onload="alert('hello');">Page to be decorated</body>
</html>
所用myLayout布局:
<html>
<head>
<script src="global.js" />
<g:layoutHead />
</head>
<body onload="${pageProperty(name:'body.onload')}"><g:layoutBody /></body>
</html>
输出结果:
<html>
<head>
<script src="global.js" />
<script src="myscript.js" />
</head>
<body onload="alert('hello');">Page to be decorated</body>
</html>
4.在Controller 中指定 Layout
class BookController {
static layout = 'customer'
def list() { … }
}
5.服务端 Includes,在view中使用include
<g:include controller="book" action="list" />
6.使用Content Blocks 标签
在装饰页中
<content tag="navbar">book</content>
在布局中
<g:pageProperty name="page.navbar" />
会输出 book