[opencms-dev] menu help needed
William Kernos
williamk at koorong.com.au
Thu Aug 24 07:29:47 CEST 2006
Hey ppl I have been developing a small site with open cms but am now
struggling,
Based on a few examples & my very limited experience in coding I have come
up with the code below that does breadcrumbs & builds a sitemap. I now need
this modified to only print out top level menu options except if you are in
a sublevel menu in which case it needs to expand the menu option under only
the top level menu item that you are under.
For example:
Say your overall sitemap looked like
Folder1
Page1
Page2
Page3
Folder2
Page1
Page2
Page3
Then you clicked on Page 2 under Folder2 the staemap would look something
like this
Folder1
Folder2
Page1
Page2
Page3
If that makes any sense to you.
The only way I can see to do this is create a tree structure using the
navigation elements but I don't want to reinvent the wheel if there is an
easier way of doing it, or if someone has some code I could use.
Any help would be greatly appreciated.
Regards,
Will
// Create a JSP action element
org.opencms.jsp.CmsJspActionElement cms = new
CmsJspActionElement(pageContext, request, response);
String filename, foldername, filenameparam;
// Get the current folder name
filename = cms.getRequestContext().getUri();
if ((filenameparam = request.getParameter("filename")) == null)
{
foldername =
org.opencms.file.CmsResource.getFolderPath(filename);
}
else
{
foldername =
org.opencms.file.CmsResource.getFolderPath(filenameparam);
String foldernameprop = cms.property("target",
filename);
if (foldernameprop != null) foldername =
foldernameprop + foldername;
}
// Declare some variables
String rootFolder = "/";
String moduleFolder = "/system/modules/modulename/";
//3: site navigation
java.util.List list =
cms.getNavigation().getNavigationBreadCrumb();
list = cms.getNavigation().getSiteNavigation("/", -1);
CmsJspNavElement element = null;
element =
cms.getNavigation().getNavigationForResource(filename);
int currentLevel = 0;
int level;
String resourceName;
if (filename.endsWith("/index.html"))
{
filename = filename.substring(0,filename.length() -
10);
}
for (java.util.Iterator i = list.iterator(); i.hasNext();)
{
CmsJspNavElement ne = (CmsJspNavElement)i.next();
level = ne.getNavTreeLevel();
resourceName = ne.getResourceName();
if (ne.isInNavigation())
{
if (level > currentLevel)
{
out.println("<ul
class=\"level" + level + "\">\n");
currentLevel = level;
}
if (level < currentLevel)
{
out.println("</ul>\n");
currentLevel = level;
}
if (filename.equals(resourceName))
{
out.println("<li
class=\"active\">" + ne.getNavText() + "</li>\n");
continue;
}
else
{
out.println("<li>");
}
out.println("<a href=\"" +
cms.link(resourceName) + "\">" + ne.getNavText() + "</a></li>\n");
}
}
for (int i = 0; i < (currentLevel-1); i++)
{
out.println ("</ul>");
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20060824/2b9e47d8/attachment.htm>
More information about the opencms-dev
mailing list