Lesson 6. Recent Elvis Sightings, cont.

Zope cannot find the tutorial examples. You should install the tutorial examples before continuing. Choose "Zope Tutorial" from the product add list in the Zope management screen to install the examples.

If you have already installed the tutorial, you can either follow along manually, or reinstall the tutorial examples. Note: make sure that you have cookies turned on in your browser.

So we've seen that the sightings.html page is built from objects in the sightingsFolder folder. How does it work?
  1. Click the sightings.html template to edit it.
  2. Change the contents of the template to:
    <html>
    
    <h1 tal:content="template/title">title</h1>
    
    <table border="1">
      <tr tal:repeat="sighting container/sightingsFolder/objectValues">
        <td tal:content="structure sighting">
          Sighting goes here
        </td>
      </tr>
    </table>
    
    </html>
  3. Click the Save Changes button.
  4. Click the Test tab.

Notice how each sighting now has a box drawn around it.

What's going on? The tal:repeat statement iterates over a list of sightings. The list is defined by the expression container/sightingsFolder/objectValues. The expression calls the objectValues method of the sightingsFolder folder. It returns all the objects contained by a folder.

Notice the sighting part of the repeat statement. It is a local variable that takes the value of each object in the list in turn. This variable is used by the the tal:content statement to insert the contents of each file object inside the table.

Summary

You can programmatically build web pages with groups of objects by looping over them and inserting them.

In the next lesson you'll learn about how to manage and display pictures.