Attention

This document was written for an old version of Plone, Plone 3, and was last updated 863 days ago.

To learn how to upgrade to the current version of Plone, read the upgrade manual.

Moving a viewlet from a viewlet manager to another one

by David Convent last modified Jan 11, 2010 09:38 PM
The title says it all…

To achieve moving a viewlet from a viewlet manager to another one, we'll have to apply what we already covered in the previous paragraphs:

We have to hide the viewlet from the viewlet manager that we want to take it out from, and register it to the other viewlet manager for the zSubject that corresponds to our theme.

Let's assume that we want to move the portal actions from top to bottom…

in browser/interfaces.py, we need to setup our ZSubject:

from plone.theme.interfaces import IDefaultPloneLayer

class IMyThemeSpecific(IDefaultPloneLayer):
    """Marker interface that defines a ZSubject.
       It will be used for the viewlets that we want to add to the
       "My Theme" skin only.
    """

in browser/configure.zcml:

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

    <interface
        interface=".interfaces.IMyThemeSpecific"
        type="zope.publisher.interfaces.browser.IBrowserSkinType"
        name="My Theme"
        />

    <!-- Moved viewlet registration -->
    <browser:viewlet
        name="plone.site_actions"
        manager="plone.app.layout.viewlets.interfaces.IPortalFooter"
        class="plone.app.layout.viewlets.common.SiteActionsViewlet"
        permission="zope2.View"
        layer=".interfaces.IMyThemeSpecific"
        />

</configure>

in profiles/default/viewlets.xml:

<?xml version="1.0"?>
<object>
  <order manager="plone.portalfooter" skinname="My Theme"
         based-on="Plone Default">
    <viewlet name="plone.site_actions" insert-after="*" />
  </order>
  <!-- We hide the one we want to move -->
  <hidden manager="plone.portalheader" skinname="My Theme">
    <viewlet name="plone.site_actions" />
  </hidden>
</object>

Done!

All we did, we did it without touching main_template.pt, isn't it a success?


Contribute

Something wrong or out of date? Anybody can edit or create a new article in the knowledge base. Simply create an account on this site, log in, and click the Edit button to contribute.