Portlet
Plone Theme Reference
1. Anatomy of a Portlet
The bits that go to make up a portlet renderer (which is the bit of a portlet you'll want to customize).
Customizing a portlet is similar to overriding a viewlet, but rather more straightforward. There is a specific ZCML directive for customization.
Directive in ZCML
<plone:portletRenderer />
Attributes in ZCML
- layer
- a marker interface for your particular theme
- portlet
- the interface of the portlet you wish to customize
- template
- location of the template you wish to override
- class
- your custom class (use this if you don't specify a template) for rendering the portlet
2. Moving, Removing or Hiding a Portlet
Some tips on moving or hiding portlets.
Whether or not portlets appear on your site is highly customizable through the web, you can use the manage portlets link in most contexts. For more information:
It's assumed that you wouldn't want to fix portlets on a page (otherwise they'd probably be viewlets). However, if you wish to set up an initial assignment of portlets on installation of your theme product, use
- [your theme package]/profiles/default/portlets.xml.
Here's an extract from the Plone Default portlets.xml, setting up the login and navigation portlet for the left-hand column, and the review and news portlets for the right-hand column.
<?xml version="1.0"?> <portlets xmlns:i18n="http://xml.zope.org/namespaces/i18n" i18n:domain="plone"> <!-- Assign the standard portlets --> <assignment manager="plone.leftcolumn" category="context" key="/" type="portlets.Navigation" name="navigation" /> <assignment manager="plone.leftcolumn" category="context" key="/" type="portlets.Login" name="login" /> <assignment manager="plone.rightcolumn" category="context" key="/" type="portlets.Review" name="review" /> <assignment manager="plone.rightcolumn" category="context" key="/" type="portlets.News" name="news" /> </portlets>
The attributes for the assignment directive are described in full here: http://plone.org/products/plone/roadmap/203/. In brief:
- manager and type
- The names for these can be looked up in plone.app.portlets.portlets.configure.zcml (for type of portlet) or in the Plone Default profiles/default/portlets.xml file.
- category
- This can be one of four values "context", "content_type", "group" or "user" - depending on where you wish to assign your portlets.
- key
- This will depend on the value given in category above. In the case of "context", the location in the site is indicated (the examples above specify the site root).
If you wish to configure the portlet in more detail, you can nest property directives within the assignment directive. Here's a tweak to ensure the navigation portlet appears at the root of the site:
<assignment name="navigation" category="context" key="/" manager="plone.leftcolumn" type="portlets.Navigation"> <property name="topLevel">0</property> </assignment>
3. Overriding a Portlet
A quick cheat sheet of how to override or customize a portlet.
Through the Web
- Use Site Setup > Zope Management Interfaces > portal_view_customizations to customize the template of an existing Plone Default portlet.
In your own product
There is a detailed tutorial available here:
You can also look up the details of the portlet you want to override in the Elements section of this manual.
Quick Cheat Sheet
You will need to know the name of
- Your theme-specific interface
- This is optional but ensures that your portlet is only available for your theme. If you used the plone3_theme paster template, then the name will probably be IThemeSpecific.
You will need to create the following (you should be able to locate the originals to copy by looking them up in the Elements section):
- plone portlet renderer directive
- [your theme package]/browser/configure.zcml
- page template
- [your theme package]/browser/[your template name].pt
- Python class *
- [your theme package]/browser/[your module name].py
* in most cases you won't need a Python class
Sample configuration.zcml directive
<configure
xmlns:plone="http://namespaces.plone.org/plone">
<include package="plone.app.portlets" />
<plone:portletRenderer
portlet="[element interface]"
template="[your template name].pt"
(or class=".[your module].[your class name]")
layer="[your theme specific interface]"
/>
</configure>
Sample Python class for navigation portlet override
If you want to customize the navigation portlet, you may need to supply the class as well as the template. Two templates are involved: the first is the usual display template; the second handles the recursion through the navigation tree. If you need to make your own version of the second, then you'll need to assign it to the recurse method in the class.
from plone.app.portlets.portlets.navigation import Renderer
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
class [your class name](Renderer):
_template = ViewPageTemplateFile([your template name].pt)
recurse = ViewPageTemplateFile([your recurse template name])4. Override the portlets in Plone 3.0
Customizing the portlets is a regular task, working with Plone theme. In this how-to we will find out how-to do this in Plone 3.0 with it's new mechanism for managing portlets (contributed by Denys Mishunov)

Author: