Extracting a DIV's content using Sitemesh Decorators
I would like to know how I can extract the content of a specific DIV using decorators, instead of using <decorator:body />
wh开发者_开发问答ich will fetch all the content inside the <body>
tag.
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
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.
SiteMesh comes with com.opensymphony.module.sitemesh.multipass.DivExtractingPageParser. It's limited in functionality; it only extracts the divs one level below the body.
精彩评论