Views I – Mastering Plone 5 development

Views I

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

A simple browser view#

Before writing the talk view itself we step back and have a brief look at 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 <configure
 2   xmlns="http://namespaces.zope.org/zope"
 3   xmlns:browser="http://namespaces.zope.org/browser"
 4   xmlns:plone="http://namespaces.plone.org/plone"
 5   i18n_domain="ploneconf.site">
 6
 7   <!-- Set overrides folder for Just-a-Bunch-Of-Templates product -->
 8   <include package="z3c.jbot" file="meta.zcml" />
 9   <browser:jbot
10     directory="overrides"
11     layer="ploneconf.site.interfaces.IPloneconfSiteLayer"
12     />
13
14   <!-- Publish static files -->
15   <browser:resourceDirectory
16     name="ploneconf.site"
17     directory="static"
18     />
19
20   <browser:page
21     name="training"
22     for="*"
23     template="templates/training.pt"
24     permission="zope2.View"
25     />
26
27 </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...