0

Well, I'm trying to make a navigation menu for a website that takes automatically its values from the folders structure of the website. I'm using opencms navigation tags. The structure is something like:

  • Menu1
  • Menu2
    • Submenu 2.1
    • Submenu 2.2
      • Submenu 2.2.1
    • Submenu 2.3 .....

What I want is to get all the elements to be able to display always the same menu, no matter the level you are inside at that moment, with the submenus in a dropdown way.

The problem is that I'm only able to display elements from the same level you are in through "forFolder" tag. Or I can display the whole tree (with "treeForFolder"), but also just until the level you are in, e.g. if you are at Submenu2.2, it won't display Submenu 2.2.1...

<cms:navigation type="treeForFolder" var="nav" startLevel="2" endLevel="5"/>
<ul class="nav navbar-nav">
<c:forEach items="${nav.items}" var="elem">
<li><a href="<cms:link>${elem.resourceName}</cms:link>" class="${clase}">${elem.navText}</a></li>
</c:forEach>
</ul>

How could I achieve my purpose? StartLevel and EndLevel params won't change anything, because it will display just until your current level of navigation.

I would like to do it using cms nav tags, and not directly through java.

Thanks in advance!

2 Answers2

0

You can use the type forSite.

Like this:

<cms:navigation type="forSite" startLevel="0" endLevel="3" var="nav"/>

Look at the API: CmsJspNavigationBean

Ben
  • 290
  • 2
  • 17
0

I don't know if you still need it (just found it now), but here is the code for my navigation-menu, and i think it helps you too:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    import="org.opencms.jsp.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms"%>

<div id="subNav">
    <cms:navigation var="nav" type="treeForFolder" startLevel="2" endLevel="5" />
    <c:set var="oldLevel" value="" />
    <c:forEach items="${nav.items }" var="element">
        <c:set var="currentLevel" value="${ element.navTreeLevel}" />
        <c:choose>
            <c:when test="${empty oldLevel })"></c:when>
            <c:when test="${currentLevel > oldLevel }">
                <ul class="dropMenu">
            </c:when>
            <c:when test="${currentLevel == oldLevel }">
                </li>
            </c:when>
            <c:when test="${currentLevel < oldLevel }">
                <c:forEach begin="${currentLevel+1 }" end="${oldLevel }">
                    </li>
                    </ul>
                </c:forEach>
                </li>
            </c:when>
        </c:choose>
        <c:choose>
            <c:when
                test="${fn:startsWith(cms.requestContext.uri, element.resourceName)}">
                <c:set var="elementClass">activeNavigation</c:set>
            </c:when>
            <c:otherwise>
                <c:set var="elementClass">default</c:set>
            </c:otherwise>
        </c:choose>
        <c:set var="navText">${ element.navText}</c:set>
        <c:if test="${empty navText or fn:contains(navText, '??? NavText') }">
            <c:set var="navText">${element.title }</c:set>
        </c:if>
        <li><a class="${elementClass}" href="<cms:link>${element.resourceName}</cms:link>">${navText}</a>
        <c:set var="oldLevel" value="${currentLevel }"></c:set>
    </c:forEach>
    <c:if test="${!empty oldLevel}">
        </li>
        </ul>
    </c:if>
</div>

This tree lists as follows:

  • Menu 1
  • Menu 2
    • Submenu 2.1
    • Submenu 2.2
      • Submenu 2.2.1
      • Submenu 2.2.2
    • Submenu 2.3

where the selected menu-point is bold.

I hope that's what you're looking for. :)

Edit: Oh, and if you want more depth, you can just increase the endLevel.