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.
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
which, when rendered, displays the current URL:
You are currently viewing the URL
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:
<form action="formHandler" method="POST">
<input type="text" size="20" name="name">
favourite sandwich filling
<input type="text" size="15" name="filling">
<input type="submit" name="submit" value="Hit Me"><br>
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>.
<span tal:replace="request/form/filling">filling type here</span>
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!