Personal tools
You are here: Home Documentation Tutorials Customization for developers 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

Viewlets

Customising Zope 3 viewlets

Martin Aspeli

This tutorial provides an overview of how to customise different aspects of Plone 3
Page 6 of 7.

Viewlets are snippets of a page, written a bit like a view but composed into the page via a viewlet manager. The viewlet manager is responsible for finding, ordering, filtering and rendering its viewlets. Most of Plone's standard viewlets are found in the plone.app.layout package. Here is an excerpt from its viewlets/configure.zcml file:

    <browser:viewlet
        name="plone.colophon"
        for="*"
        manager=".interfaces.IPortalFooter"
        template="colophon.pt"
        permission="zope.Public"
        />

The name is unique within the portlet manager, which is identified by an interface (and defined earlier in the same file, using a <browser:viewletManager /> directive). Here, we are using a template-only viewlet, defined for any context, and not protected by any particular permission. It is possible to define a class instead of or in addition to the the template.

As you may have guessed, it's possible to customise the viewlet either by registering a new viewlet with the same name, in the same manager, but for a more specific context. Alternatively, we can register a new viewlet with the same name, in the same manager, using a custom layer. That could look like this:

    <browser:viewlet
        name="plone.colophon"
        for="*"
        manager="plone.app.layout.viewlets.interfaces.IPortalFooter"
        template="funny_colophon.pt"
        permission="zope.Public"
        layer=".interfaces.IExampleCustomization"
        />

Notice how we have turned the relative module path to the IPortalFooter viewlet manager interface into an absolute one and specified a new template (found relative to the directory where our new ZCML file is located).

Finally, it's possible to use the view attribute to specify an interface or class of a page view. With this type of customisation, you can have a viewlet that looks different on different pages. The most common use of this in Plone is to register viewlets that are only shown on the main "view" of a page, by using the special IViewView marker interface, which is applied to the current view during traversal if the user is looking at the "view" tab of the current context. Here is an example from plone.app.layout.viewlets:

    <browser:viewlet
        name="plone.comments"
        for="Products.CMFCore.interfaces.IContentish"
        manager=".interfaces.IBelowContent"
        view="..globals.interfaces.IViewView"
        class=".comments.CommentsViewlet"
        permission="zope2.View"
        />

As with views, you can of course use the for, layer and view customisation dimensions in combination.

Finding viewlets

The portal_view_customizations tool will show you viewlet registrations (and the viewlet managers they are registered for). As with views, you can hover over the viewlet name to see where it is registered in a tool tip. To discover the name of a particular viewlet, you can use the @@manage-viewlets view, e.g. as http://localhost:8080/plone/@@manage-viewlets.

For more information about viewlets, see the tutorial on customising the viewlets in main_template.

 
by Martin Aspeli last modified January 15, 2008 - 00:11 All content is copyright Plone Foundation and the individual contributors.

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