我可以将身体属性(而不是孩子)拉到我的sitemesh / freemarker装饰器中吗?

时间:2012-10-25 03:44:27

标签: java freemarker sitemesh

我们正在使用包含以下示例内容的网页:

<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>元素,那么它们不会被简单地丢弃吗? / p>

1 个答案:

答案 0 :(得分:1)

好的,我经过一些实验后最终找到了答案:D身体属性进入page.properties["body.attrName"],你可以在我的情况下使用它,如下所示:

<#if page.properties["body.class"]??>
    <body class="${page.properties["body.class"]}">
<#else>
    <body>
</#if>