我们使用的页面包含以下示例内容:
<html>
<head>
<title>Page Title</title>
<!-- (page-specific JS and styles) -->
</head>
<body>
<h1>Page Title</h1>
<!-- (rest of page content) -->
</body>
</html>然后使用SiteMesh + Freemarker,我们用这样的东西来装饰它们:
<!doctype html>
<html>
<head>
<title><#if title?? && title?has_content>${title}</#if></title>
<!-- (global styles and scripts)-->
${head}
</head>
<body>
<!-- (Header elements) -->
${body}
<!-- (Footer elements) -->
</body>
</html>我想知道的是,是否有一种很好的方法将页面级<body>元素上的任何额外属性传播到装饰器的<body>元素,这样它们就不会被简单地丢弃?
发布于 2012-10-25 14:13:08
好吧,经过一些实验,我最终自己找到了答案:D body属性放入page.properties["body.attrName"]中,您可以在我的示例中使用它,如下所示:
<#if page.properties["body.class"]??>
<body class="${page.properties["body.class"]}">
<#else>
<body>
</#if>https://stackoverflow.com/questions/13061236
复制相似问题