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

Switching Things Around - Zope

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

  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


Now that you know how variables work, it's time to examine the TAL"condition" attribute, which lets you add decision-making capabilitiesto your templates. In this section, I'll be examining conditionalexpressions and comparison operators, and demonstrating, with practicalexamples, how they can be used to craft more intelligent code.

Let's begin with a simple example:
<span tal:define="global switch string:on"></span><span tal:condition="switch">You left the light switch on</span>
In this case, the visibility of the second <span> depends on thepresence or absence of the "switch" variable. If the variable ispresent, the second <span> will be displayed; if not, it will remainhidden.

All this happens via the special TAL "condition" attribute, which,according to the TAL specification, is used to "...include a particularpart of a Template only under certain conditions, and omit itotherwise". This TAL attribute is thus analogous to the traditional "if"statement found in all programming languages, and it can come in veryhandy when you need to add control flow routines to your templates.

The expression provided to the "condition" attribute must be a validTALES expression, which evaluates to either true or false.

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