[ZPT] Re: why is default false?

Barry A. Warsaw barry@wooz.org
Thu, 23 May 2002 17:58:46 -0400


I'll point out that I was playing around with the Zope Book's section
on ZPT and I tried to write this:

-------------------- snip snip --------------------
...
<style type="text/css">
...
   .square {
        background: #DDDDDD
    }
</style>
<table border="1" cellpadding="5" cellspacing="0">
<tr tal:repeat="row python:range(10)">
  <td class="square"
      tal:repeat="col python:range(10)"
      tal:attributes="class python:row==col and default or nothing">
     <span tal:define="x repeat/row/number;
                       y repeat/col/number;
                       z python:x*y"
           tal:replace="string:$x * $y = $z"
           >blah</span>
  </td>
</tr>
</table>
-------------------- snip snip --------------------

This fails to DWIM because the Python expression in the tal:attributes
always evaluates to nothing.  /That's/ because default is false. :(

So I ended up with the following:

-------------------- snip snip --------------------
<table border="1" cellpadding="5" cellspacing="0">
<tr tal:repeat="row python:range(10)">
  <td class="square"
      tal:repeat="col python:range(10)"
      tal:attributes="class python:row==col and 'square' or nothing">
     <span tal:define="x repeat/row/number;
                       y repeat/col/number;
                       z python:x*y"
           tal:replace="string:$x * $y = $z"
           >blah</span>
  </td>
</tr>
</table>
-------------------- snip snip --------------------

which works, but which I don't like <wink>.  Changing Default to a
true value (in lib/python/TAL/DummyEngine.py and
Products/PageTemplates/TALES.py) sees to do what I want, and doesn't
cause failures in the test suite.

-Barry