Grails 技巧 - View 篇

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

转载于:https://my.oschina.net/linghuchong/blog/139321

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值