Reordering and Hiding viewlets

by David Convent last modified Jan 11, 2010 09:36 PM

How to simply change the viewlets behavior from a Generic Setup Profile.

We saw in the previous paragraph that viewlets ordering is stored in a utility. That utility is set up from the viewlets.xml file of a Generic Setup profile.

Ordering

If all you need is to reorder the viewlets in the PloneDefault skin, you can simply copy the original viewlets.xml from CMFPlone/profiles/default/ into MyTheme/profiles/default/, and edit the copied file to make it reflect your needs.

But you may want to order viewlets with more flexibility. Be happy: there are handy parameters for each node in viewlets.xml.

Let's see how would look a viewlets.xml file for a 3rd party theme product:

<?xml version="1.0"?>

<object>

  <order manager="plone.portalheader" skinname="My Theme"
         based-on="Plone Default">
    <viewlet name="plone.logo" insert-before="*"/>
  </order>
  <order manager="plone.portaltop" skinname="*">
    <viewlet name="plone.app.i18n.locales.languageselector"
             insert-after="plone.path_bar"/>
  </order>

</object>

The above code contains two <order/> declarations: The first one creates a new skin named MyTheme which is based on the PloneDefault one. This means that the new skin inherits from the viewlets ordering of the skin it is based on. In our example, the plone.logo is moved at the first position in the plone.portalheader viewlet manager. The second declaration moves plone.app.i18n.locales.languageselector right after plone.path_bar in the plone.portaltop viewlet manager for all skins (notice the skinname="*" statement).

Note

Both DIYPloneStyle and ZopeSkel add a viewlets.xml file when generating a blank theme product (use --add-viewlet-example with the DIYPloneStyle generator script).

For your convenience, you can find inline documentation about the parameters that can be used in the generated file (It is an option with ZopeSkel, answer 'True' when it asks for it).

Hiding

Hiding a viewlet is also done from the viewlets.xml with the <hidden/> node which is at same level as <order/>, and is done per skin selection.

For instance, if you need to remove the global sections for your skin, you'd have to add some declaration like the following one to viewlets.xml:

<hidden manager="plone.portalheader" skinname="My Theme">
  <viewlet name="plone.global_sections" />
</hidden>

Unhiding

If, for any reason, you need to unhide one or more viewlets for a given viewlet manager, you can make use of the purge and remove node parameters in your <hidden/> declaration in viewlets.xml.

To unhide all hidden viewlets for a given viewlet manager:

<?xml version="1.0"?>
<object>
  <hidden manager="plone.portalheader" skinname="Plone Default"
          purge="True" />
</object>

To unhide specific viewlet(s):

<?xml version="1.0"?>
<object>
  <hidden manager="plone.portalheader" skinname="Plone Default">
    <viewlet name="plone.global_sections" remove="True" />
  </hidden>
</object>
Note
The purge and remove node parameters are also supported inside the <order/> declaration.

Nothing that difficult here ;-)