Home arrow Zope arrow Page 5 - ZPT Basics (part 1)

Putting It All In Context - Zope

Contrary to what you might think, DTML isn't the only programming language available to you in Zope. Take a look at Zope Page Templates (ZPT), a template-based alternative that makes it easier for designers and developers to collaborate on Zope application development.

  1. ZPT Basics (part 1)
  2. The Power Of Three
  3. Practical Magic
  4. Anatomy Lesson
  5. Putting It All In Context
By: Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 23
September 18, 2002

print this article


You'll remember that I told you, a while back, that every TALES path expression must begin with a variable name. The TALES specification defines a number of such variables - here's a list of the most important ones:

"nothing" - a null value

"repeat" - a built-in TALES variable used for repetition

"root" - the starting point for the object hierarchy

"here" - the current context

"template" - the template itself

"container" - the template's container

"request" - the request object

You've already seen the "template" context in action - now let's take a look at the "request" context, which contains information about the current HTTP request. Consider the following example,

You are currently viewing the URL <i tal:content="request/URL">URL comes here</i>.
which, when rendered, displays the current URL:

You are currently viewing the URL http://medusa:8080/ZPT%20Basics/MyFirstTemplate.
This context also comes in handy when you're building Web forms and need to access the values of the various form variables. Consider the following simple DTML Document:

Please enter the following details: <br> <form action="formHandler" method="POST"> <p> Your name <br> <input type="text" size="20" name="name"> <br> </p> <p> Your favourite sandwich filling <br> <input type="text" size="15" name="filling"> <br> </p> <input type="submit" name="submit" value="Hit Me"><br> </form>
This displays the following form to the user.

Next, create the form processing script, "formHandler", using a Page Template:

Hello, <span tal:replace="request/form/name">name here</span>. I like <span tal:replace="request/form/filling">filling type here</span> sandwiches too. Maybe we should exchange recipes.
Try it out - here's an example of what you might see:

The beauty of this example lies in its simplicity. I've used the "request" context and obtained access to the form variables simply by specifying the appropriate path - the "request/form/name" path for the form variable "name", and the "request/form/filling" path for the form variable "filling".

And that's about it for this first part of the series. In this article, I gave you a gentle introduction to the ZPT way of doing things, explaining the special "content" and "replace" TAL attributes. In the next segment, I'll be looking at a few more of TAL's special attributes, including the ones that let you define variables and write conditional statements. Make sure you tune in for that one...and until then, stay healthy!

Note: All examples in this article have been tested on Linux/i586 with Zope 2.5.0. Examples are illustrative only, and are not meant for a production environment. Melonfire provides no warranties or support for the source code described in this article. YMMV!

>>> More Zope Articles          >>> More By Harish Kamath, (c) Melonfire

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


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