Views - Parte I

In this part you will:

  • Register a view
  • Create and use a template for the view

Topics covered:

  • zcml

Una simple vista browser

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 another view similar to the demoview already there:

 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
28
29
30
31
32
33
34
35
36
<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="demoview"
    for="*"
    class=".views.DemoView"
    template="templates/demoview.pt"
    layer="ploneconf.site.interfaces.IPloneconfSiteLayer"
    permission="zope2.View"
    />

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

</configure>

Add a file browser/templates/training.pt

<h1>Hello World</h1>

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

Nota

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...