Personal tools
You are here: Home Documentation Tutorials Customizing the viewlets in main_template Reordering and Hiding viewlets
Support

Get Help

Join our chat rooms or support forums if you have more specific questions.

Plone Training
Learn how to design, build, and deploy a website in Plone through one of the numerous Plone training sessions around the world.
Find Plone training…
 
Document Actions

Reordering and Hiding viewlets

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

David Convent

Since Plone 3.0, main_template.pt calls viewlet managers instead of METAL macros. Learn from this tutorial how viewlets can be programmatically reordered, hidden or added (from a product on the filesystem).
Page 3 of 7.

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 Plone Default 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 My Theme which is based on the Plone Default 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 ;-)

 
by David Convent last modified September 4, 2007 - 20:38 All content is copyright Plone Foundation and the individual contributors.

A note on uninstaling/installing the product for changes to take effect

Posted by Renier Morales at October 12, 2007 - 06:22
Thanks for a very helpful article.
Just to suggest adding a note about uninstalling/reinstalling the product containing your changes in the site setup page. I couldn't make my changes to viewlets.xml take effect until I did this.

changes to take effect ?

Posted by wandis at October 16, 2007 - 07:46
hi,

yes, can you propose a procedure for changes to be correctly updated ?
do we need only to uninstall/reinstall product ? restart plone ?

Thanks
Emmanuel

Help !!!

Posted by wandis at October 25, 2007 - 08:05
Renier ? how do you procede after change order in viewlets.xml ?

only uninstalling/reinstalling product ?

i try many things (install/restart/uninstall etc ..) but order still the same, my change are not take into account ...
thanks for help

changes

Posted by David Convent at October 25, 2007 - 10:49
if you modify a file in the profiles directory,
you need to follow this path in order to get changes applied:
- Restart the Zope server
- Go to Site Setup > Addon products > uninstall/reinstall your theme

Problems with changes not taken in account were experienced with Plone 3.0.1, but I could not reproduce anymore on Plone 3.0.2.

Make sure you have latest Plone stable release.

still issue in 3.0.2

Posted by wandis at October 27, 2007 - 16:46
hi,

i installed a fresh Plone 3.0.2 on my ubuntu box.

Plone 3.0.2
CMF-2.1.0
Zope (Zope 2.10.4-final, python 2.4.4, linux2)
Python 2.4.4 (#1, Oct 27 2007, 16:43:26) [GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)]
PIL 1.1.6

i add product DotNetTheme, apply theme ... all is working perfect

BUT

i change the viewlets.xml to
<?xml version="1.0"?>
<object>
<order manager="plone.portalheader" skinname="DotNet Example"
based-on="Plone Default">
<viewlet name="dotnet.logo" insert-before="plone.searchbox" />
</order>
<order manager="plone.portaltop" skinname="DotNet Example"
based-on="Plone Default">
<viewlet name="plone.personal_bar" insert-before="*" />
</order>
<hidden manager="plone.portalheader" skinname="DotNet Example">
<viewlet name="plone.logo" />
<viewlet name="plone.global_sections" />
</hidden>
</object>


after restarting Zope/uninstall/reinstall product the logo do not change order according last viewlets.xml changed.

feel to contact me for more detail ...


refresh

Posted by danielle d'avout at October 28, 2007 - 08:01
if you enable the auto refresh for your product, Zope will scan for any change as long as you change the version.txt, no need to restart zope : refresh the product in the quickinstaller panel.

version.txt still no refresh

Posted by wandis at October 29, 2007 - 17:30
i change the version.txt and reinstall the product but still the same.

<order manager="plone.portalheader" skinname="DotNet Example"
based-on="Plone Default">
<viewlet name="dotnet.logo" insert-before="plone.searchbox" />
</order>

The dotnet.logo still before plone.site_actions.
(i'm going to be crazy ....)

thanks for help

reordering

Posted by David Convent at October 29, 2007 - 19:43
i'm talking your problem seriously, just don't have free time right now

i'll investigate on it

thanks

Posted by wandis at October 29, 2007 - 19:54
let me know if need more details or log access to my dev environment.

Re: A note on uninstaling/installing the product for changes to take effect

Posted by Matthew Glubb at November 9, 2007 - 14:58
Hope this might help others (3.0.2):

You first of all need to change version.txt. After this, go to the Products control panel. It should detect that the version of your product has changed and ask you if you want to re-install it. Click on the re-install button and your viewlets.xml changes will be reflected.

In my view, this is a diasterous way to manage the process of developing a theme. I can only speak for myself, but pretty much the first thing that I want to do with a Plone installation for a client is to implement their theme. It is a really slow process when you have to keep repeating the process above to see changes. I would prefer to see some kind of debug mode for products that avoided this process.

viewlet problems with plone 3.02

Posted by bbutler at October 30, 2007 - 16:20
I have been working with Plone 3.02 and the viewlets, using a DIYPloneStyle product and working with the viewlet.xml file as shown in this article. I've had inconsistent results; I'll be able to hide a viewlet, but then unable to unhide. I've tried all the examples on this page and really put some effort into trying to figure out what the issue is. Sometimes viewlets show, but then I can't repeat it.
I've been changing the verson number like someone here suggested, and that works ok for reinstalling the product. I've also done it with restarting Zope, and uninstalling and reinstalling the product. Thanks for any ideas or fixes!

Hiding vs removing

Posted by unset at November 22, 2007 - 13:38
Is it good practise to remove a viewlet from a skin by just deleting its line in viewlets.xml?

Won't work

Posted by David Convent at November 22, 2007 - 14:48
This will not work because of the way Zope 3 viewlets work.
By default in Zope 3, all viewlets are rendered, but no order is applied.
The Plone 3 layer added to Zope viewlets make them appear that way: Plone first renders ordered viewlets in the right order, then remaining registered ones which order is not defined in the tool.
The only way to remove a viewlet from its viewlet manager is to declare it in the hidden node of viewlets.xml.

For any issues with the web site functionality, please file a ticket.

Please consult the policy on plone.org content if you want your content published on this site.

Servers and hosting by