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

seb bacon seb@jamkit.com
21 Mar 2002 12:40:35 +0000


On Thu, 2002-03-21 at 12:32, Janko Hauser wrote:
> On 21 Mar 2002 11:56:56 +0000
> seb bacon <seb@jamkit.com> wrote:
> 
> > 
> >   <span tal:define="thing python:namespace.get('thing', 'defaultval')">
> > 
> 
>     <div tal:define="u template/test| string:default">
>       <span tal:content="u">the default value</span>
>     </div>
> 
> This might help, if I understand the problem.

<span define="foo python:1">
     <b tal:define="bar template/foo | default"
        tal:content="bar">Foo</b>
</span>

close but no cigar: the above displays the default value.  The variable
'foo' has not been pushed onto the 'template' namespace.

incidentally, the reason I need to do this is because I'm trying to
parameterise my macros, thus:

1. Macro definition:

<p metal:define-macro="foo"
   tal:define="bar mynamespace/bar | python:[]">
 <span tal:repeat="item bar">
   stuff
 </span>
</p>


2: Using it with a parameter:

<div tal:define="bar python:['a','b','c']">
 <p metal:use-macro="foo">
   My macro goes here
 </p>
</div>

cheers,

seb