[ZPT] how do I test the existence of a variable?

Casey Duncan casey@zope.com
Thu, 21 Mar 2002 09:22:55 -0700


seb bacon wrote:
[snip]
> 
> 1. Macro definition:
> 
> <p metal:define-macro="foo"
>    tal:define="bar mynamespace/bar | python:[]">
>  <span tal:repeat="item bar">
>    stuff
>  </span>
> </p>

Perhaps this example is not capturing everything you want, but I don't 
see why you would want to default `bar' to and empty list and iterate 
over it (which would do nothing anyway). How about:

<metal:block metal:define-macro="foo">
   <p tal:condition="bar | nothing">
     <span repeat="item bar">
       ..
     </span>
   </p>
</metal:block>

the condition would then check for the existence of bar and also make 
sure it was non-empty.

If I'm not capturing this problem well enough, tell me the specific use 
case.

-Casey