Expand all trees

The sitemap on a Plone 5 website shows all of the folders expanded and all of the items within. How can I generate a navigation menu with all of the folders expanded at all times so any item can be linked to without having to first click on its parent?

The navigation is usually provided by a so called "navigation portlet". Maybe, it already has a parameter which does what you want (but likely not). Otherwise, you might look at its implementation (--> "plone.app.portlets.portlets.navigation") and derive your own portlet that does what you want (the base function is "plone.app.layout.navigation.navtree.buildFolderTree" which is also used for the site map).

What is the usecase here? A Plone site may contain lots of items, a Plone may contain various levels of folders. The limited horizontal and vertical space of the portlet slot is unlikely to fit lots of items and a deep folder structure.


Maybe collective.portlet.sitemap can help (Plone 5 compatibility is probably undone).
BTW: this will be a performance nightmare.

1 Like

regardless of the use case, is this possible?

I have been trying to show a fully expanded navtree in 4.2 as i only have 20 items or so total (and I want quick access to them all), and I can't get it to work. I have changed the "Navigation Tree Depth" from 0, right up to 5, and still only 1 layer of depth shows.

The "Navigation Tree Depth" may be designed as the maximal expansion depth (i.e. you cannot (manually) expand further) and not the "minimal expansion depth" (i.e. automatically expanded to that depth).

You definitely can get a fully expanded tree (the "site map" likely already gives you that) - but it may be necessary to create your own view or portlet for this.

If you want this in the top menu (and not in the portlet), you can use webcoutier.dropdownmenu and 'disable the css and javascript'.
if you want it in a portlet, collective.portlet.sitemap (as @keul said) is what you want.

You could also use diazo to include the sitemap .

If you need to make a view (I can not see many reasons to do this), you might be able to use some code I have here:


There is no such option in the default navigation portlet.

Beside your use case - quick access to items - another is to provide a navigation structure for dropdown menus or mobile navigation. To avoid performance penalities, one can cache the results. I've done this quite often, as this is a very common use case.

You can, as @keul said, use https://github.com/collective/collective.portlet.sitemap , or an addon I created: https://github.com/bluedynamics/bda.portlet.sitenavigation/ (with special support for Lineage sites and different caching strategy)
Another addon for such a purpose is: https://github.com/collective/webcouturier.dropdownmenu/ (replaces the global section viewlet).

And if you just want to use the default portlet, but expanded just overwrite the query builder adapter like:

in your configure.zcml:

  <includeOverrides file="overrides.zcml" />

in your overrides.zcml

      factory=".overrides.CustomQueryBuilder" />

And in overrides.py

from zope.interface import implements, Interface
from zope.component import adapts
from plone.app.portlets.portlets.navigation import QueryBuilder
from plone.app.layout.navigation.interfaces import INavigationQueryBuilder
from plone.app.portlets.portlets.navigation import INavigationPortlet
from plone.app.layout.navigation.root import getNavigationRoot

class CustomQueryBuilder(QueryBuilder):
    adapts(Interface, INavigationPortlet)

    def __init__(self, context, portlet):
        super(CustomQueryBuilder, self).__init__(context, portlet)
        rootPath = getNavigationRoot(context, relativeRoot=portlet.root)
        # navtree not 1 for sitemap like expanded trees
        self.query['path'] = {'query': rootPath}