Per Erik Strandberg /cv /kurser /blog

In this tutorial we will learn how to add elements to our plone pages, making something like this appear in your site:
http://www.pererikstrandberg.se/blog/plone/viewlet_part_one.png

There are a number of things we will not learn about viewlets - but we will get somewhere to start.

Files needed

Only need three files are needed to do this:

__init__.py
configure.zcml
skins/myviewlet_footer.pt

__init__.py

The __init__.py-file only contains a comment. This can be considered good practice since it is otherwise easy for a user to remove blank files.

skins/myviewlet_footer.pt

This is a typical Plone page template (as seen in for example: Plone Archetypes View Template Modifications) and contains nothing fancy:

<p>
  This page is <b tal:content="request/URL">URL</b>
</p>

As you can see we print the url of the present file and then a link to the Plone Cms page in my blog.

configure.zcml

The configure.zcml file contains the real action. It hooks zope and the page template together.

First let's see the important contents and then we will slowly walk through:

<configure ... >

  <browser:viewlet
    name="myviewlet.myviewlet_footer"
    for="*"
    manager="plone.app.layout.viewlets.interfaces.IPortalFooter"
    template="skins/myviewlet_footer.pt"
    permission="zope.Public"
    />

</configure>

As we can see we define a browser:viewlet (so we need the browser namespace). These are the following attributes:

Limitations

Things we might want to be able to control that are not covered in this tutorial include:


See also: Plone Cms
This page belongs in Kategori Programmering