Navigation portlet: all childen always expanded

。_饼干妹妹 提交于 2019-12-14 03:53:50

问题


How can I make the navigation portlet show children even for unselected folders? I mean initial tree state is fully expanded (at least for one level, ie: direct children).

I'm looking at INavtreeStrategy, SitemapNavtreeStrategy and INavigationQueryBuilder but no insights so far.


回答1:


I got it looking at Products/CMFPlone/browser/sitemap.py

I just had to use its query builder instead. Here's the code:

from Acquisition import aq_inner
from zope.component import getMultiAdapter

from plone.memoize.instance import memoize

from plone.app.layout.navigation.interfaces import INavtreeStrategy
from plone.app.layout.navigation.navtree import buildFolderTree

from plone.app.portlets.portlets import navigation
from Products.CMFPlone.browser.navtree import SitemapQueryBuilder


class Renderer(navigation.Renderer):

    @memoize
    def getNavTree(self, _marker=[]):
        context = aq_inner(self.context)
        **queryBuilder = SitemapQueryBuilder(context)**
        strategy = getMultiAdapter((context, self.data), INavtreeStrategy)

        return buildFolderTree(context, obj=context, query=queryBuilder(), strategy=strategy)

Then I registered a portlet renderer with:

<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:browser="http://namespaces.zope.org/browser"
    xmlns:plone="http://namespaces.plone.org/plone">

  <include package="plone.app.portlets" />


  <plone:portletRenderer
      portlet="plone.app.portlets.portlets.navigation.INavigationPortlet"
      layer="..browser.interfaces.IThemeSpecific"
      class=".navigation.Renderer"
      />

</configure>



回答2:


See the documentation of ExtendedPathIndex

http://plone.org/products/extendedpathindex

A combination of navtree and depth parameter should give you what you need.



来源:https://stackoverflow.com/questions/6312007/navigation-portlet-all-childen-always-expanded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!