Lesson 9. Elvis, Up Close and Personal

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.

People who come to your
site want a personal relationship with Elvis. You can provide this
by tailoring your site to the needs and preferences of your viewers.
Let's add the ability to bring new Elvis sightings to the attention
of site visitors. This way when a visitor comes to your site they'll
immediately know which sightings are new since they last visited.

Click the sightings.html template to edit it.

Click the Test tab to view it.

All the sightings should be
marked as new.

Reload the page.

Now none of the sightings should be marked as new. This is because
you've already seen them.

Now you've created a new sighting. Let's see if it is marked as new
by the sightings page.

Click the sightings.html page in the lesson9 folder.

Click the Test tab.

Sure enough our new sighting is marked new.

How does this work? It uses HTTP Cookies. When you visit the
sightings.html page a cookie is set that records the current
time. Then each time you return to the page sightings that are newer
than the cookie will be marked as new.

Let's look at
how this works.

Click the sightings.html template to view its contents.

Notice that the page uses the tal:define statement to defines a
lastVisit variable. It is defined by calling the lastVisit.py
script. This variable holds the time that the user last visited the
page as recorded in a cookie.

Later in the template this time is compared to the modification time
of each sighting object. If the sighting is new then it is marked as
such by including a bold tag. The bold tag uses the tal:condition
statement to optionally include its contents. In this case the
condition checks to see whether the bobobase_modification_date of
the sighting is newer than the last visit. This strangely named
method keeps track of the last modification date of Zope objects.

Now let's examine the
lastVisit.py script.

Click on the lastVisit.py script to view it.

Notice how it includes comments explaining its functioning. Comments
begin with a number sign. The script does two things: it retrieves a
cookie from the request, and it sets a new cookie using the
response.

Summary

You can use cookies to personalize a web page. Zope templates
can dynamically control their presentation.