Creating Navigation

From OpenCms Wiki
(Difference between revisions)
Jump to: navigation, search
(added breadcrumbs)
 
(4 intermediate revisions by 4 users not shown)
Line 9: Line 9:
 
You can create them using the CmsJspNavBuilder.  Here is an example:
 
You can create them using the CmsJspNavBuilder.  Here is an example:
  
 +
<code lang="Java">
 +
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> > ");
 +
}
 +
</code>
  
CmsJspActionElement element = new CmsJspActionElement(pageContext, request, response);
+
== Navigation in current folder ==
List breadcrumbParts = element.getNavigation().getNavigationBreadCrumb();
+
 
Iterator i = breadcrumbParts.iterator();
+
To get a list of the items that are available in the current folder, you use the getNavigationForFolder method:
String path = "";
+
 
while(i.hasNext()) {
+
<code lang="Java">
        CmsJspNavElement el = (CmsJspNavElement)i.next();
+
<%@ page import="java.util.*, org.opencms.jsp.*" %>
        path += el.getFileName();
+
<ul>
        if(el.isInNavigation()) out.print("<a href=\"" + path + "\">" + el.getNavText() +"</a> > ");
+
  <%
}
+
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>
 +
</code>
 +
 
 +
== Module Simple Navigation ==
 +
A module which contains some JSP tags to create navigations. It was developed 5 years ago but still works. The documenation is there in docbook.
 +
[https://bitbucket.org/shimberger/opencms-simplenav] 
 +
 
 +
 
 +
[[Category:Developing in OpenCms]]

Latest revision as of 13:22, 6 March 2013

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>

Module Simple Navigation

A module which contains some JSP tags to create navigations. It was developed 5 years ago but still works. The documenation is there in docbook. [1]

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox