[ZPT] TALES

Evan Simpson evan@4-am.com
Wed, 12 Feb 2003 13:26:58 -0600


Jim Fulton wrote:
> I'm surprised you can have a tales expression after the "|".

The ability to have a TALES expression as the final alternate was added 
in Dec. 2001 as a result of a discussion I can't find anywhere.  Hmm.  I 
also have an apparently bogus memory of documenting the new grammar.

> I think that this is a bad idea, especially since you didn't
> even say what "defer" does, which, I guess, is in keeping with
> it's undocumentedness. :)

It's an experimental expression type usable to defer evaluation of other 
expressions.  "defer:<foo>" evaluates to a callable object.  This object 
returns the value of the deferred expression in the current context, so 
for example:

<div tal:define="xis defer:string:x is $x">
   <p tal:repeat="x python:range(3)"
      tal:content="xis"></p>
</div>

...evaluates to:

<div>
   <p>x is 0</p>
   <p>x is 1</p>
   <p>x is 2</p>
</div>

> I also didn't think that "|" caught *all* exceptions. Does it?

No, just (Undefined, AttributeError, KeyError, TypeError, IndexError, 
Unauthorized) at the moment.

> I think the right answer to this question is to write a Python script

I agree.

Cheers,

Evan @ 4-am