对于sitemesh3,官方只给出了<title><head><body> 三个标签,但是对于一些特殊的需求是远远不能满足的,好了,不废话了,进入正题:
本文章是基于java类来配置的,先建好sitemesh的配置类SiteMeshFilter ,如下:
public class SiteMeshFilter extends ConfigurableSiteMeshFilter {
@Override
protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
//customer decorator
builder.addTagRuleBundle(new CustomTagRuleBundle());
}
}
接下来是CustomTagRuleBundle,如下:
public class CustomTagRuleBundle implements TagRuleBundle {
@Override
public void install(State defaultState, ContentProperty contentProperty, SiteMeshContext siteMeshContext) {
defaultState.addRule("myfooter", new ExportTagToContentRule(siteMeshContext, contentProperty.getChild("myfooter"), false));
}
@Override
public void cleanUp(State defaultState, ContentProperty contentProperty, SiteMeshContext siteMeshContext) {
}
}
到此为止,就可以了接下里就是解释,
“myfooter” 是我自定义的标签名字,如果需要多个,则只需要在install里面多添加一条addRule;
下面是母页面的引用:
<body>
<sitemesh:write property='body'/>
<div class="footer">
<p align="center">© 2016 仙飞 版权所有 </p>
</div>
<sitemesh:write property='myfooter'/>
</body>
只贴了body部分,其他的也不重要;
下面是子页面的引用:
<body>
<myfooter>
自定义页脚
</myfooter>
</body>