[Hippo-cms7-user] Linking faceted navigation into your sitemenu

d.clayton d.clayton at lukkien.com
Thu Oct 13 14:28:08 CEST 2011


Hi Mathijs,

I managed to get faceted navigation into my menu as it is in the website I'm
porting. Thanks for the pointer :)

I'm now just wondering if there's a better way of doing the following: I
want the sitemenu link that's the current document to be highlighted in some
way (e.g. bold text instead of a hyperlink, like the rest of the leftmenu
works). Unfortunately because I'm passing a set of beans in instead of a
HstSiteMenu, it doesn't know which item is selected. So, my solution is to
do getContentBean(request) and get the bean's name, then do a string
comparison in the JSP of the bean name with the facet item name. This works
- but it seems quite clunky, and I don't really like that I'm now loading
the content bean twice per request. Here's my code:

In my Menu.java:

        // get faceted nav
        String facetLocation = getParameter("facetLocation", request);
        String facetParentName = getParameter("facetParentName", request);
        if(facetLocation != null && facetParentName != null) {
        	HippoItem item =
getSiteContentBaseBean(request).getBean(facetLocation);
	        if(item != null) {
	            String facetNodeType = getParameter("facetNodeType", request);
	            String nodeType = DEFAULT_NODE_TYPE;
	            if(facetNodeType != null) {
	            	nodeType = facetNodeType;
	            }
	            HippoBean content = getContentBean(request);
	            request.setAttribute("contentName", content.getName());
	        	request.setAttribute("facetResult",
item.getChildBeans(DEFAULT_NODE_TYPE));
	        	request.setAttribute("facetParentName", facetParentName);
	        }
        }

And my JSP (inside an iterated siteMenuItem):

              <c:if test="${item.name == facetParentName}">
                   <c:if test="${fn:length(facetResult) gt 0}">
					    <ul id="left-nav">
					        <%-- at elvariable id="facetResult"
type="java.util.List<org.hippoecm.hst.content.beans.standard.HippoFolder>"--%>
					        <c:forEach items="${facetResult}" var="facet">
					        	<c:choose>
						        	<c:when test="${not empty facet.title}">
					                    <c:set var="title" value="${facet.title}"/>
					                </c:when><c:otherwise>
					                	<c:set var="title" value="${facet.name}"/>
					                </c:otherwise>
					            </c:choose>
					            <c:choose>
					        	<c:when test="${facet.name == contentName}">
					        		<li>*${title}*</li>
					        	</c:when>
					        	<c:otherwise>
						            <li>&lt;a href=&quot;&lt;hst:link
hippobean=&quot;${facet}&quot;/&gt;"><c:out value="${title}"/> </li>
						        </c:otherwise>
						        </c:choose>
					        </c:forEach>
					    </ul>
					  </c:if>
				</c:if>

Do you have any comments or suggestions on this approach? In particular, is
there a better way to determine which facet item should be styled
"selected"?

Thanks again!



--
View this message in context: http://hippo.2275632.n2.nabble.com/Linking-faceted-navigation-into-your-sitemenu-tp6881055p6888719.html
Sent from the Hippo CMS 7 mailing list archive at Nabble.com.



More information about the Hippo-cms7-user mailing list