Chapter 13.1.3. Control Structures

Of course, no template system would be complete without conditional display and looping. Kid provides these through the py:if, and py:for processing directives. If you know Python, you already pretty much know how these work.

So, for example, the value of a py:if expression is false for all the same expressions where it would be false in Python. That is, py:if="x" is false if x is (1) an empty string, dictionary, or list; or (2) if x is 0, and 3 if x is the Boolean value False.

When a py:if statement evaluates to false, Kid removes the tag that it is an attribute of, along with all of its descendant elements.

In other words if the expression evaluates to anything false in Python, the tag and all its children ...

Get Rapid Web Applications with TurboGears: Using Python to Create Ajax-Powered Sites now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.