2

How I can reorder the portlets so that inherited, parent portlets come before the current item's portlets?

2 Answers 2

5

Mathias solutions seem to be the easier ones; anyway I want to leave this documented in case you don't want to install a third party product.

You can change the way portlets are ordered just by writing an adapter. The following one, for instance, reorder the portlets on any object providing the IATImage interface (images) so the content type portelts are rendered first, then the group ones, and the context ones at last:

from plone.portlets.interfaces import IPortletManager
from plone.portlets.interfaces import IPortletRetriever
from plone.portlets.retriever import PortletRetriever as BaseRetriever
from Products.ATContentTypes.interfaces import IATImage
from zope.component import adapts
from zope.interface import implements


class PortletRetriever(BaseRetriever):
    implements(IPortletRetriever)
    adapts(IATImage, IPortletManager)

    def getPortlets(self):
        assignments = super(PortletRetriever, self).getPortlets()
        context = [p for p in assignments if p['category'] == 'context']
        group = [p for p in assignments if p['category'] == 'group']
        content_type = [p for p in assignments if p['category'] == 'content_type']
        new_assignments = content_type + group + context
        return new_assignments

Don't forget to register your adapter using the following on your ZCML file:

<configure xmlns="http://namespaces.zope.org/zope">
  ...
  <adapter factory=".adapters.PortletRetriever" />
  ...
</configure>
1
  • This, however, does not answer how to have inherited (context) portlets appear first.
    – malthe
    Feb 8, 2018 at 12:59
4

There are two solutions I'm aware of

collective.weightedportlets

You can define a weight for each portlet, no matter in which section/group the portlet is (user, context, type, inherited). Version 1.1 is Plone 4.3 compatible.

Solgema.PortletsManager

Basically does a similar thing like collective.weightedportlets, but it can be done by D'n'D and it extends the UI of manage-portlets.

Of yours you could hack into the portlet retriever, but I'm not recommend that.

PS: If you want to write your own portlet retriever, also check collective.weightedportlets :-)

More about how plone renders portlets.

3
  • nice! I didn't knew about collective.weightedportlets; I'm going to add CI on it later :-)
    – hvelarde
    Feb 27, 2015 at 11:27
  • What do you mean by CI? Mar 1, 2015 at 10:24
  • Solgema.PortletsManager is great. This would be nice core functionality! (Didn't try the other one) Mar 1, 2015 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.