【发布时间】:2011-07-16 19:50:42
【问题描述】:
我正在尝试做这样的事情:
对于 /admin/* 的所有请求,我需要使用 B 装饰器来装饰页面,而且 B 装饰器必须包含在作为主要应用程序布局的 A 装饰器的内容中。
如何使用 Sitemesh 做到这一点?
有可能吗?还是我必须在 B 装饰器中从 A 重复相同的布局?
提前致谢
【问题讨论】:
我正在尝试做这样的事情:
对于 /admin/* 的所有请求,我需要使用 B 装饰器来装饰页面,而且 B 装饰器必须包含在作为主要应用程序布局的 A 装饰器的内容中。
如何使用 Sitemesh 做到这一点?
有可能吗?还是我必须在 B 装饰器中从 A 重复相同的布局?
提前致谢
【问题讨论】:
回答我自己的问题。是的,有可能:
使用我自己的例子,这是装饰器 b 被装饰器 a 装饰。
<page:applyDecorator name="a">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Decorator B</title>
<decorator:head/>
</head>
<body id="page-home">
This is a test.
</body>
</html>
</page:applyDecorator>
【讨论】:
这是使用 freemarker 的示例:
<#assign decorator = JspTaglibs["http://www.opensymphony.com/sitemesh/decorator"]/>
<#assign page = JspTaglibs["http://www.opensymphony.com/sitemesh/page"]/>
<@page.applyDecorator name="a">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Decorator B</title>
<@decorator.head/>
</head>
<body id="page-home">
This is a test.
</body>
</html>
</@page.applyDecorator>
【讨论】: