Creating Navigation

(Difference between revisions)
Jump to: navigation, search
(added "navigation in current folder" section)
Line 10: Line 10:
  
 
<code lang="Java">
 
<code lang="Java">
CmsJspActionElement element = new CmsJspActionElement(pageContext, request, response);
+
CmsJspActionElement element = new CmsJspActionElement(pageContext, request, response);
List breadcrumbParts = element.getNavigation().getNavigationBreadCrumb();
+
List breadcrumbParts = element.getNavigation().getNavigationBreadCrumb();
Iterator i = breadcrumbParts.iterator();
+
String path = "";
String path = "";
+
for(Iterator i = breadcrumbParts.iterator(); i.hasNext(); ) {
while(i.hasNext()) {
+
        CmsJspNavElement el = (CmsJspNavElement)i.next();
        CmsJspNavElement el = (CmsJspNavElement)i.next();
+
        path += el.getFileName();
        path += el.getFileName();
+
        if(el.isInNavigation()) out.print("<a href=\"" + path + "\">" + el.getNavText() +"</a> > ");
        if(el.isInNavigation()) out.print("<a href=\"" + path + "\">" + el.getNavText() +"</a> > ");
+
}
}
+
 
</code>
 
</code>
  
Line 31: Line 30:
 
CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, response);
 
CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, response);
 
List list = cms.getNavigation().getNavigationForFolder();
 
List list = cms.getNavigation().getNavigationForFolder();
Iterator i = list.iterator();
+
for (Iterator i = list.iterator(); i.hasNext(); ) {
while (i.hasNext()) {
+
 
     org.opencms.jsp.CmsJspNavElement ne = (org.opencms.jsp.CmsJspNavElement)i.next();
 
     org.opencms.jsp.CmsJspNavElement ne = (org.opencms.jsp.CmsJspNavElement)i.next();
 
     out.println("<li><a href=\"" + cms.link(ne.getResourceName()) + "\">");
 
     out.println("<li><a href=\"" + cms.link(ne.getResourceName()) + "\">");

Revision as of 20:27, 27 March 2010

Most people use CmsJspNavBuilder to create navigation menus on the fly.

Breadcrumbs

Breadcrumbs are a trail of links that indicate where you are in the hierarchy. They look like: Home >> About >> Staff

So you would know you were in the about section, looking at staff pictures.

You can create them using the CmsJspNavBuilder. Here is an example:

CmsJspActionElement element = new CmsJspActionElement(pageContext, request, response);
List breadcrumbParts = element.getNavigation().getNavigationBreadCrumb();
String path = "";
for(Iterator i = breadcrumbParts.iterator(); i.hasNext(); ) {
        CmsJspNavElement el = (CmsJspNavElement)i.next();
        path += el.getFileName();
        if(el.isInNavigation()) out.print("<a href=\"" + path + "\">" + el.getNavText() +"</a> > ");
}

Navigation in current folder

To get a list of the items that are available in the current folder, you use the getNavigationForFolder method:

<%@ page import="java.util.*, org.opencms.jsp.*" %>
<ul>
  <% 
CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, response);
List list = cms.getNavigation().getNavigationForFolder();
for (Iterator i = list.iterator(); i.hasNext(); ) {
    org.opencms.jsp.CmsJspNavElement ne = (org.opencms.jsp.CmsJspNavElement)i.next();
    out.println("<li><a href=\"" + cms.link(ne.getResourceName()) + "\">");
    out.println(ne.getNavText() + "</a></li>");
}
%>
</ul>
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox