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

Posted by Zoltan Soos at Nov 18, 2007 12:43 AM
Too bad you can not do now any of these customisations through the Plone interface. To make any chamges to the portlet you need to create your own skin and work on the file system.

As an example: how would you move the site actions from the top to the bottom without writing a skin?

RE: Lost Flexibility

Posted by Rob Porter at Nov 27, 2007 03:46 PM
You can put @@manage-viewlets at the end of your url then hit the down arrow on the site actions object. Pretty easy

RE: Lost Flexibility

Posted by Zoltan Soos at Nov 27, 2007 08:00 PM
Thanks Rob! It is slick a solution indeed. I have tried it and it works to a certain extent -- you can only move the portlet within the portal header section (ViewletManager: plone.portalheader). Now, how do you bring it down to the footer section? (ViewletManager: plone.portalfooter)?

a success ?

Posted by Darcy Clark at Mar 07, 2008 03:52 AM
I have to read a 7-part tutorial in order to tweak main_template ? I can't agree that this is better than the Plone 2.x way of doing things.

Avoid touching main_template is good

Posted by rsantos at Apr 18, 2008 10:11 PM
When you customize main_template -- I admit sometimes it's necessary though, even in Plone-3.x -- you become more vulnerable to changes in future versions of Plone.

Parametrized viewlet?

Posted by Shaun Roe at May 04, 2008 02:03 PM
Hello, I have just skimmed through your tutorial looking for an answer to my particular problem: How to display a line from an rss feed directly in the body of the page, instead of in the sidebar rss portlet. In the past I've applied a xslt template to an rss feed and then inserted it into the body (with ajax), and I assume a similar thing could be done using a viewlet to apply the xslt server-side...but I need to parametrize the viewlet on the url of the feed,and the user (or admin) should be able to change that url. Is this possible?
thanks
shaun