`
- 浏览:
410914 次
- 性别:
- 来自:
北京
-
定义页面布局(Layouts)
页面布局可以通过Grails对SiteMesh的支持来创建,有两种方法来创建页面布局,一种是在视图页面中设置名为"layout"的meta标签的值来指定需要使用的页面布局:
<html>
<head>
<meta name="layout" content="main"></meta>
</head>
<body>This is my content!</body>
</html>
现在在"grails-app/views/layouts"目录下创建名为"main.gsp"的布局就可以了!内容如下:
<html>
<head>
<title><g:layoutTitle default="An example decorator" /></title>
<g:layoutHead />
</head>
<body onload="${pageProperty(name:'body.onload')}">
<div class="menu"><!--my common menu goes here--></menu>
<div class="body">
<g:layoutBody />
</div>
</body>
</html>
这个布局使用了 GSP 标签 来将布局应用到目标页面。
GSP对于页面布局也提供了支持,这就是Layout。它是以Sitemesh为基础,同样也是GSP文件,文件位于grails-app/views/layouts。Layout定义涉及3个主要元素:
layoutTitle,输出目标页Title
layoutHead,输出目标页Head
layoutBody,输出目标页Body
使用示例:
<html>
<head>
<title><g:layoutTitle default="An example decorator" /></title>
<g:layoutHead />
</head>
<body onload="${pageProperty(name:'body.onload')}">
<div class="menu">
<!--my common menu goes here?
<div class="body">
<g:layoutBody />
</div>
</div>
</body>
</html>
其中,pageProperty,可用于输出目标页的某个属性。
对于Layout的使用,4种方式。
法1:在<head>之间使用<meta name="layout" content="main"></meta>。
法2:使用规约。通过存放位置来确定。当有多个匹配时,以详细的优先使用:
应用于Controller:grails-app/views/layouts/controller-name.gsp
Action:grails-app/views/layouts/controller-name/action-name.gsp
法3:使用Controller的layout属性
class BookController {
//该controller相关的所有view都将使用
//grails-app/views/layouts/customer.gsp为Layout
static layout = 'customer'
def list = { … }
}
法4,使用<g:applyLayout>,对内容区域、URL、template应用模板:
<g:applyLayout name="myLayout" template="bookTemplate" collection="${books}" />
<g:applyLayout name="myLayout" url="http://www.google.com" />
<g:applyLayout name="myLayout">
The content to apply a layout to
</g:applyLayout>
在GSP中使用inlcude,有以下的方式:
作为标签:<g:include controller="book" action="list"/>
或者跟applyLayout合用:
<g:applyLayout name="myLayout">
<g:include controller="book" action="list"/>
</g:applyLayout>作为方法调用:def content = include(controller:"book", action:"list")
在Layout中,我们还可以使用内容块,这将让我们可以更灵活地使用layout。它的使用分成2部分:
在Layout中使用<g:pageProperty />预留:
<div id="left1">
<g:pageProperty name="page.layout1.left.content"/>
</div>
<div id="top2">
<div id="toolbar"></div>
</div>
<div id="center2">
<g:pageProperty name="page.layout2.center.content"/>
</div>
<div id="bottom2">
<g:pageProperty name="page.layout2.bottom.content"/>
</div>
<g:pageProperty name="page.other"/>
在内容页中使用<content>填充:
<content tag="layout1.left.content"> <!-- 注意没有page前缀 -->
<div id="toc"></div>
</content>
<content tag="layout2.center.content">
<div id="terminal"></div>
</content>
<content tag="layout2.bottom.content">
<div id="helpstone"></div>
</content>
<content tag="other">
<div id="how-to" style="text-align:left;">
...
</div>
</content>
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
Grails 中文 参考手册
grails中文参考手册 学习资料 groovy
grails 中文第二版
grails 中文 API grails 中文 API
Grails1.1最新 中文 文档 当今的Java Web开发技术显得过于复杂,相对于它本身的需要来说。现在主流的Java Web框架也是异常复杂,而且没有很好的遵循 Don't Repeat Yourself (DRY) 法则。 因此我们要以一种新的思维...
当今的Java Web开发技术显得过于复杂,相对于它本身的需要来说。现在主流的Java Web框架也是异常复杂,而且没有很好的遵循 Don't Repeat ...本文档将带你从Grails入门开始,最终能够使用Grails框架建设Web应用程序。
Grails Grails Grails Grails Grails
grails 中文文档+grails-fckeditor-0.9.5.zip插件
grails中的上传,下载,需要的请下载
Grails 最新的 v1.1版的中文文档,chm格式,Grails是一套快速开发Web应用的开源框架,基于Groovy编程语言,并构建于Spring、Hibernate和其它标准Java框架之上,能为大家带来超高效率的一站式框架。
比较难找的grails的资料,我也是找了很久才找到的。需要grails相关的拿走
Grails 中文参考手册 Grails 中文参考手册
比较详细的grails中文文档,有所有命令行解释,还有grails的一个完整的学习过程的资料
grails 中文手册,grails应该不用说明是啥东西了吧,流行的脚本语言groovy应用框架。
Grails权威指南Grails权威指南Grails权威指南Grails权威指南Grails权威指南Grails权威指南
grails 中文帮助 中文帮助grails 中文帮助 中文帮助grails 中文帮助 中文帮助grails 中文帮助 中文帮助
这个是我在开发中用到的技术,很多都是第一次使用。