Basic recipe for a Five view

This recipe is addressed more to the zope2/plone developer with a bit of knowledge of the zope3 universe, but not much experience in implementing the new practices.

Simply put, Five views are just like TTW python scripts, except without the limited forced security, and with the possibility to integrate them in unit testing and adapt them to other protocols then just http.

First, things should be done the newly recommended "Zope3 ways". That means creating a new package under the Products folder, or, if pythonproducts is used, anywhere in the python packages path.

Let's name this package "views_test". Make it a python package by placing an empty file inside. We'll place the views under a 'browser' package, so we need to create a new folder called 'browser' with an empty file as well.

Inside the browser package, we'll create a 'testing' module, with the following content:

from zope.interface import Interface, implements
from Products.CMFPlone import utils

class ITesting(Interface):
    def drink():
        """Drinks the cool aid"""

class Testing(utils.BrowserView):

    def drink(self):
portal_url = context.portal_url()
        return "We drank the cool aid at %s" % portal_url

The interface declaration is not needed, and it's not necesary for the view to implement a certain interface, but it makes documenting, configuring and possibly future extending the software easier.

Configuring zope to load the view

Best practices is to place configuration files (configure.zcml) in the closest package to which they belong, so we'll have to configure zope to look in the 'browser' package for zcmls as well. To do this, edit the views_test/configure.zcml file and place a simple directive to load the browser package.

<include package=".browser" />
The configure.zcml file for the browser package will contain
<configure xmlns=""



The TAL template, is like this:

    <title tal:content="template/title">The title</title>
  <body tal:define="view context/@@testing_view">
<span tal:content="view/drink" />

It doesn't use the standard main_template macros, but this can be easily integrated.