Home arrow Zope arrow 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.

TABLE OF CONTENTS:
  1. ZPT Basics (part 2)
  2. A Little Male Bonding
  3. The Number Game
  4. A Question Of Scope
  5. Switching Things Around
  6. Comparing Apples and Oranges
  7. If It's Thursday, It Must be Italy
  8. Submitting To The King
  9. Looking Ahead
By: Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 13
September 25, 2002

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
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
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

ZOPE ARTICLES

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