ZPT Basics (part 2) - The Number Game (
Page 3 of 9 )
Remember how I told you TALES expressions need not only be paths, but
can be Python expressions too? Here's an example of how that might work:
<h1>10 * 34 is <i tal:define="product python:10*34"
tal:replace="string:$product">Product here</i>.</h1>
In this case, instead of using the "string" keyword, I've used the
"python" keyword, which instructs Zope to evaluate the Python expression
and store the result in the variable "product". Here's the output:
10 * 34 is 340
You can define more than one variable at a time as well - take a look:
<h1>The name's <i tal:define="firstname string:Robin;lastname
string:Hood" tal:content="string:$lastname, $firstname $lastname">name
here</i>.</h1>
As you can see, in order to define two variables in a single statement,
you simply need to separate them with a semi-colon (;). Here's the
output:
The name's Hood, Robin Hood.