使用 Sitemesh 装饰器提取 DIV 的内容

发布于 2024-09-24 03:58:55 字数 113 浏览 10 评论 0原文

我想知道如何使用装饰器提取特定 DIV 的内容,而不是使用 来获取 内的所有内容; 标签。

I would like to know how I can extract the content of a specific DIV using decorators, instead of using <decorator:body /> which will fetch all the content inside the <body> tag.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

眼泪淡了忧伤 2024-10-01 03:58:55

我正在使用的 sitemesh 版本 2.4.2 是可能的。在 christian grobmeier 所以这是我的 sitemesh.xml

<sitemesh>
  <property name="decorators-file" value="/WEB-INF/decorators.xml"/>
  <excludes file="${decorators-file}"/>

  <page-parsers>
    <parser content-type="text/html" class="com.opensymphony.module.sitemesh.parser.HTMLPageParser"/>
  </page-parsers>

  <page-parsers>
    <parser content-type="text/html" class="com.opensymphony.module.sitemesh.multipass.DivExtractingPageParser"/>
  </page-parsers>

  <decorator-mappers>
    <mapper class="com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper">
        <param name="config" value="${decorators-file}"/>
    </mapper>
  </decorator-mappers>
</sitemesh>

这是我的 home.ftl 的 mainlayout.jsp 片段的片段

  <div id="container" style=" padding-top: 60px; ">
            <div id="leftbar">

                <div style="height:400px;">
                    <img src="<spring:url value='/images/Logo.png'/>" class="logo"/>
                </div>

                <decorator:getProperty property="div.side-menu"/>
                <%--<decorator:body />--%>
            </div>
            <div>
                <decorator:getProperty property="div.top"  />
            </div>
            <div>
                <decorator:getProperty property="div.content"  />
            </div>
        </div>

(使用 freemarker)

<div id="side-menu">
  <ul>
    <li class="current"><a href="/home">All</a></li>
      <#list genre as gen >
        <li><a href="/category?cat=${gen}">${gen}</a></li>
     </#list>
</ul>
</div>


<div id="top">
  <ul id="slider" class="architectorSlider">
     <li>
        <img src="<@spring.url '/images/slide_1.jpg'/>" alt="" class="slide-image"/>
        <img src="<@spring.url '/images/slider/timthumbf014.jpg'/>?src=<@spring.url '/images/slide_1.jpg' />&w=100&h=42&zc=1"
             alt="" class="slide-thumbnail"/>
    </li>
  </ul>
 </div>

我希望这能让你继续前进,如果还不算太晚的话:D

It's possible with the version 2.4.2 of sitemesh that i'm using.Found the anwser on christian grobmeier so here is my sitemesh.xml

<sitemesh>
  <property name="decorators-file" value="/WEB-INF/decorators.xml"/>
  <excludes file="${decorators-file}"/>

  <page-parsers>
    <parser content-type="text/html" class="com.opensymphony.module.sitemesh.parser.HTMLPageParser"/>
  </page-parsers>

  <page-parsers>
    <parser content-type="text/html" class="com.opensymphony.module.sitemesh.multipass.DivExtractingPageParser"/>
  </page-parsers>

  <decorator-mappers>
    <mapper class="com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper">
        <param name="config" value="${decorators-file}"/>
    </mapper>
  </decorator-mappers>
</sitemesh>

here is a snippet of my mainlayout.jsp

  <div id="container" style=" padding-top: 60px; ">
            <div id="leftbar">

                <div style="height:400px;">
                    <img src="<spring:url value='/images/Logo.png'/>" class="logo"/>
                </div>

                <decorator:getProperty property="div.side-menu"/>
                <%--<decorator:body />--%>
            </div>
            <div>
                <decorator:getProperty property="div.top"  />
            </div>
            <div>
                <decorator:getProperty property="div.content"  />
            </div>
        </div>

snippet of home.ftl (using freemarker)

<div id="side-menu">
  <ul>
    <li class="current"><a href="/home">All</a></li>
      <#list genre as gen >
        <li><a href="/category?cat=${gen}">${gen}</a></li>
     </#list>
</ul>
</div>


<div id="top">
  <ul id="slider" class="architectorSlider">
     <li>
        <img src="<@spring.url '/images/slide_1.jpg'/>" alt="" class="slide-image"/>
        <img src="<@spring.url '/images/slider/timthumbf014.jpg'/>?src=<@spring.url '/images/slide_1.jpg' />&w=100&h=42&zc=1"
             alt="" class="slide-thumbnail"/>
    </li>
  </ul>
 </div>

i hope this can get you going if it's not too late :D

甜心 2024-10-01 03:58:55

NB Black Sensei 在下面发布了更好的答案。

我认为这是不可能的。 Sitemesh 是一个非常基本的模板系统,它的标签很少——总共五个。这里有一个完整的列表 装饰器 taglib

您可能想看看另一个如果您需要这种程度的控制,可以使用模板系统。

NB Black Sensei has posted a better answer below.

I don't think this is possible. Sitemesh is a pretty basic templating system that has very few tags - five in all. There's a full list here decorator taglib

You might want to look at another templating system if you need that level of control.

假装爱人 2024-10-01 03:58:55

SiteMesh 附带 com.opensymphony.module.sitemesh.multipass.DivExtractingPageParser。它的功能有限;它只提取 body 下面一层的 div。

SiteMesh comes with com.opensymphony.module.sitemesh.multipass.DivExtractingPageParser. It's limited in functionality; it only extracts the divs one level below the body.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文