我想实现以下功能:
对于所有请求/admin/*,我需要使用B装饰器来装饰页面,但是B装饰器也必须包含在A装饰器的内容中,A装饰器是主应用程序布局。
如何使用Sitemesh实现这一点?
这是否可能?还是我必须在B装饰器中重复A中的相同布局?
谢谢。
![布局](https://istack.dev59.com/whYFC.webp)
如何使用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>