Home arrow Zope arrow Page 2 - Creating Basic Zope Applications

Categories - Zope

While some people immediately understand the usefulness of Zope, others don't understand how to apply their skills. In this article, Peyton McCullough explains how to apply the skills to create a simple forum.

TABLE OF CONTENTS:
  1. Creating Basic Zope Applications
  2. Categories
  3. Topics
  4. Replies
By: Peyton McCullough
Rating: starstarstarstarstar / 19
January 25, 2005

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

 

All right, let's get to work. Create a folder called "forum" with the title "My Forum." This will be our forum's main folder. All of our forum's files should be created in our main folder. Create the folders 1, 2 and 3 with the titles Category One, Category Two and Category Three, respectively. These are our forum's categories.

 

Next, we need to create an index page with a list of categories. Before we do that, however, let's create a macro to define a basic layout. If you're not too familiar with Zope Page Templates, a macro provides a common look and feel. Say you wanted every page in your site to have a header and footer, yet you need to update the style of the header and footer frequently. You could simplify this process by using a macro. Create a Zope Page Template named base and insert the following text:

 

<html metal:define-macro='base'>

   <head>

      <title tal:content='container/title'>Page Title</title>

   </head>

   <body>

      <h1 metal:define-slot='title'>Title</h1>

      <span metal:define-slot='content'>Content</span>

      <br />

      Copyright &copy; 2004 Your Website Name Here

   </body>

</html>

 

Our macro will allow us to replace "Title" and "Content" with the appropriate text.

 

Now we'll create the list of categories. Since the separation of presentation and logic is encouraged in Zope, we will use both Zope Page Templates and Python to accomplish this. Create a Zope Page Template object named index_html and insert the following text:

 

<span metal:use-macro='container/base/macros/base'>

   <h1 metal:fill-slot='title' tal:content='container/title'>Title</h1>

   <span metal:fill-slot='content'>

      <span tal:replace='structure container/getCategories'></span>

   </span>

</span>

 

Our macro, base, governs index_html's look.

 

As you can see, index_html calls the file getCategories. This will be a Python script that retrieves the list of categories and formats it. Create a Script ( Python ) Object named getCategories with the following text:

 

for category in container.objectValues():

   if category.meta_type == 'Folder':

      print '<a href=\'%s/cat\'>%s</a><br />' % ( category.getId(), category.getProperty ( 'title' ) )

return printed

 

If you are not familiar with Python, this script retrieves the objects in its folder. If the object is a folder, it treats it as a category and outputs a link to the file cat with the category's folder as cat's context.

 



 
 
>>> More Zope Articles          >>> More By Peyton McCullough
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

ZOPE ARTICLES

- Creating Zope Products
- Plone Content Types With Archetypes
- Flat User Management in Zope
- Creating Basic Zope Applications
- Getting started with Zope for Linux and Sola...
- ZPT Basics (part 4)
- ZPT Basics (part 3)
- ZPT Basics (part 2)
- ZPT Basics (part 1)
- Exception Handling In DTML
- DTML Basics (part 4)
- DTML Basics (part 3)
- DTML Basics (part 2)
- DTML Basics (part 1)
- Using Zope With Apache

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: