Plone: Getting NavTreePortlet to Display Always 2 Sublevels
Yes, another of those boring technical posts. Trying in Plone to display a NavTreePortlet with always the first and second level of the navigation tree shown. Plus the current page highlighted. Found a hackish solution, but it may not be 100% what other people need. Basically we are switching to "sitemap" mode, set the sitemap depth to 2, and patch NavTreePortlet to highlight the current page in sitemap mode too. Here it comes...
First step is to switch to "sitemap" mode. So customize "portlet_navtree_template" and change the first div with the tal:define of "data" as such:
<div class="portletContent odd" tal:define="data here/getSitemapData">Now go to settings of the NavTreePortlet and change "Depth of sitemap" to "2" (or whatever you like). I believe this will not show sublevels below that, but I may be wrong, haven't actually tested.
This will change the display of the navigation tree a lot, but the downside is that the current item is not highlighted any more. (The current item gets another css class assigned, so by changing that in ploneCustom.css we can alter the appearance of the current item.) We need a fix in the actual code of the NavTreePortlet:
*** NavTreePortlet.py_orig 2005-06-26 08:52:49.000000000 +0200
--- NavTreePortlet.py 2005-06-26 08:48:23.000000000 +0200
***************
*** 54,59 ****
--- 54,61 ----
if context == self or sitemap:
currentPath = getToolByName(self, 'portal_url').getPortalPath()
query['path'] = {'query':currentPath, 'depth':self.getSitemapDepth()}
+ # trying to fix detection of current item in sitemap mode
+ currentPath = '/'.join(context.getPhysicalPath())
else:
currentPath = '/'.join(context.getPhysicalPath())
query['path'] = {'query':currentPath, 'navtree':1}
Apply this patch to NavTreePortlet.py in the INSTANCE_HOME/Products/NavTreePortlet directory with something like
patch -p0 < navtree_sitemap_highlight.patchAs usual this change is at your own risk and you better know what you are doing :-)