这是我的问题的编辑,首先是如何在同一个 gsp 页面中应用 2 个布局,但现在我遇到了 3 个布局的问题 :):
我对所有 css 和布局的东西都很陌生,我正在使用 grails 2.0 版本
我的问题中有以下模块:
1. main.gsp 布局,基本上所有页面都有一个带有公司 Logo 的漂亮标题。
2. mainTabPanle.gsp 布局,基本上包含一些所有页面都应该有的主标签
3. reportTab.gsp 布局,基本上包含漂亮的报告选项卡和简短的 javascript 代码来操作所有报告 gsp 页面应具有的所选选项卡颜色。
我要做的是在所有报告 gsp 页面中使用此 reportTab 布局。
所以这就是我到目前为止得到的:
主.gsp:
<!doctype html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="${resource(dir: 'css', file: 'main.css')}"type="text/css">
<g:layoutHead/>
<r:layoutResources />
</head>
<body style="height:100%">
<div>some nice header in here </div>
<g:layoutBody/>
<r:layoutResources />
</body>
</html>
<g:applyLayout name="main">
<!doctype html>
<html>
<head>
<g:layoutHead/>
<r:layoutResources />
</head>
<body>
<div>some main tabs here </div>
<g:layoutBody/>
</body>
<script type="text/javascript">
//script to manipulate main tabs
</script>
<r:layoutResources />
</body>
</html>
</g:applyLayout>
<g:applyLayout name="mainTabPanel">
<!doctype html>
<html>
<head>
<g:layoutHead/>
<r:layoutResources />
</head>
<body>
<div>some reports tab panel </div>
<g:layoutBody/>
</body>
<script type="text/javascript">
//some script to manipulate report tab item
</script>
<r:layoutResources />
</body>
</html>
</g:applyLayout>
<meta name="layout" content="reportTabPanel" />
<meta name="layout" content="mainTabPanel" />
最佳答案
您可以在同一页面上应用 2 个布局。为了在布局文件中应用不同的布局,您需要使用 applyLayout 标签。你的 reportTab 应该是这样的:
<g:applyLayout name="main">
<!doctype html>
<head>
<g:layoutHead/>
<r:layoutResources />
</head>
<body>
<div> some nice tabs here </div>
<g:layoutBody/>
</body>
<script type="text/javascript">
few line script handling chosen tab color in here
</script>
<r:layoutResources />
</body>
</html>
</g:applyLayout>
https://stackoverflow.com/questions/9629155/