【问题标题】:Can I pull body attributes (rather than children) up into my sitemesh/freemarker decorator?我可以将 body 属性(而不是子属性)拉到我的 sitemesh/freemarker 装饰器中吗?
【发布时间】:2012-10-15 04:51:51
【问题描述】:

我们正在使用具有以下示例内容的页面:

<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>

我想知道是否有一种很好的方法可以将页面级 &lt;body&gt; 元素上的任何额外属性传播到装饰器的 &lt;body&gt; 元素,这样它们就不会被简单地丢弃?

【问题讨论】:

    标签: java freemarker sitemesh


    【解决方案1】:

    好的,经过一些实验,我最终自己找到了答案:D body 属性进入page.properties["body.attrName"],您可以像这样在我的情况下使用它:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-31
      • 2018-03-08
      • 2018-12-03
      • 2013-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多