Home Zope Page 7 - ZPT Basics (part 2)

# If It's Thursday, It Must be Italy - Zope

Dig deeper into the world of ZPT with examples andillustrations of how to create, manipulate and use variables andconditional tests in your templates.

Rating:  / 13
September 25, 2002

SEARCH DEV SHED

TOOLS YOU CAN USE
ZPT also lets you "nest" conditional statements. For example, this isperfectly valid ZPT code:
<span tal:define="global day string:Thursday; global time string:12;global place string:Italy"></span><span tal:condition="python:day == 'Thursday'"> <span tal:condition="python:time == '12'"> <span tal:condition="python:place == 'Italy'"> How about some pasta for lunch? </span> </span></span>
I'm sure you'll agree, though, that this is both complex andfrightening. And so, in addition to the comparison operators I've usedso liberally thus far, Python also provides the "and", "or" and "not"logical operators which allow you to group conditional expressionstogether. The following table should make this clearer.

```Assume delta = 12, gamma = 12 and omega = 9
Expression                          Evaluates To
------------------------------------------------------------------------
--
delta == gamma and delta > omega    True
delta == gamma and delta < omega    False
delta == gamma or delta < omega     True
delta > gamma or delta < omega      False
not delta                           False```
Given this knowledge, it's a simple matter to rewrite the example abovein terms of logical operators:
```<span tal:define="global day string:Thursday; global time string:12;
global place string:Italy"></span>
<span tal:condition="python:day == 'Thursday' and time == '12' and place
== 'Italy'">
How about some pasta for lunch?
</span>```

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