我有一个要求创建面包屑一目了然。我有以下在 JSP 中运行良好的代码。但是我正在努力将代码转换为清晰的代码,因为我没有在 currentStyle 对象中获得正确的方法来获取“absParent”和其他。任何帮助将不胜感激!
<%@ include file="/libs/foundation/global.jsp" %>
<%
final int startLevel = currentStyle.get("absParent", 3);
final int endLevel = currentPage.getDepth() - currentStyle.get("relParent", 0);
final int minItems = currentStyle.get("minItems", 2);
if (startLevel <= endLevel - minItems) {
%><section class="breadcrumbs"><%
for (int level = startLevel+1; level < endLevel; ++level) {
Page itemPage = currentPage.getAbsoluteParent(level);
if (itemPage == null || !itemPage.isValid() || itemPage.isHideInNav()) {
continue;
}
final String pagePath = itemPage.getPath() + ".html";
final String pageTitle = itemPage.getNavigationTitle();
String className = "breadcrumb-item-"+level;
if (level == startLevel) className += " breadcrumb-first";
if (level == endLevel-1) className += " breadcrumb-last";
pageContext.setAttribute("className", className);%>
<section class="breadcrumbs ">
<a href="<%= xssAPI.getValidHref(pagePath) %>" class="breadcrumb-item"><%= xssAPI.encodeForHTML(pageTitle) %></a>
</section>
<%} %>
</section><%
}
%>