18. Views I

In this part you will:

  • Register a view that can be opened in the browser
  • Create and use a template for the view

Topics covered:

  • zcml

18.1. A simple browser view

Before writing the talk view itself we step back and talk a little about views and templates.

A view in Plone is usually a BrowserView. It can hold a lot of cool python code but we will first focus on the template.

Edit the file browser/configure.zcml and register a new view called training:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 <configure
   xmlns="http://namespaces.zope.org/zope"
   xmlns:browser="http://namespaces.zope.org/browser"
   xmlns:plone="http://namespaces.plone.org/plone"
   i18n_domain="ploneconf.site">

   <!-- Set overrides folder for Just-a-Bunch-Of-Templates product -->
   <include package="z3c.jbot" file="meta.zcml" />
   <browser:jbot
     directory="overrides"
     layer="ploneconf.site.interfaces.IPloneconfSiteLayer"
     />

   <!-- Publish static files -->
   <browser:resourceDirectory
     name="ploneconf.site"
     directory="static"
     />

   <browser:page
     name="training"
     for="*"
     template="templates/training.pt"
     permission="zope2.View"
     />

 </configure>

Add a file browser/templates/training.pt

<h1>Hello World</h1>

You now have everything in place to learn about page templates.

Note

The view training has no python class registered for it but only a template. It acts as if it had an empty python class inheriting from Products.Five.browser.BrowserView but the way that happens is actually quite a bit of magic…