Personal tools
Support

Get Help

Join our chat rooms or support forums if you have more specific questions.

Plone Training
Learn how to design, build, and deploy a website in Plone through one of the numerous Plone training sessions around the world.
Find Plone training…
 
Document Actions

Registering a view

This is where we create the Product and register our own view for folders

Daniel Nouri

Impress your colleagues by using GenericSetup and Zope 3 views efficiently and with minimal effort! This tutorial shows you how to add a new view, how to use it, how to add a new content type and how to hook it all up.
Page 2 of 5.

First, we'll create a Product called MYPRODUCT. This is how you do it: In your Zope instance's Products folder, create a MYPRODUCT folder and therein create a file called __init__.py. Leave the __init__.py empty for now.

Then, in the same folder, create a file called configure.zcml with the following contents:

<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser">

<browser:page
for="Products.ATContentTypes.interface.IATFolder"
name="my-view.html"
class=".browser.MyView"
template="my_view.pt"
permission="zope2.View"
/>

</configure>

What we did here is register a new view for the IATFolder interface with the name my-view.html. The implementation of that view goes into the class .browser.MyView, which uses the template my_view.pt. This view is guarded with the zope2.View permission.

Now we'll create that MyView class and the my_view.pt page template. Inside the MYPRODUCT folder on the filesystem, create a file called browser.py and insert the following:

from Products.Five import BrowserView

class MyView(BrowserView):
pass

This is where we will define methods later on that our template can use like view/my_method. Right now, we'll leave the view class empty.

For the template, we'll copy and modify one of the templates that comes with Plone. Let's use folder_summary_view.pt from CMFPlone/skins/plone_content and strip out everything that's in the metal:listingmacro tag so that what we have left is this:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
lang="en"
metal:use-macro="here/main_template/macros/master"
i18n:domain="plone">

<body>

<div metal:fill-slot="main">
<metal:main-macro define-macro="main">

<div metal:use-macro="here/document_actions/macros/document_actions">
Document actions (print, sendto etc)
</div>

<h1 tal:content="object_title" class="documentFirstHeading">
Title or id
</h1>

<a href=""
class="link-parent"
tal:define="parent_url python:here.navigationParent(here, template_id)"
tal:condition="parent_url"
tal:attributes="href parent_url"
i18n:translate="go_to_parent_url">
Up one level
</a>

<p class="documentDescription"
tal:content="here/Description"
tal:condition="here/Description">
Description
</p>

<p> Hello world! </p>

</metal:main-macro>
</div>

</body>
</html>

Save this as MYPRODUCT/my_view.pt.

Now start up your Zope, go into the Plone interface, create a folder called whatever and then visit .../portal/whatever/my-view.html.

 
by Daniel Nouri last modified January 30, 2007 - 17:29
Contributors: Wim Boucquaert
All content is copyright Plone Foundation and the individual contributors.

For any issues with the web site functionality, please file a ticket.

Please consult the policy on plone.org content if you want your content published on this site.

Servers and hosting by