Moving a viewlet from a viewlet manager to another one
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?
Lost flexibility
As an example: how would you move the site actions from the top to the bottom without writing a skin?