[ZPT] how do I test the existence of a variable?
Harry Wilkinson
harryw@nipltd.com
Thu, 21 Mar 2002 13:59:43 +0000
> <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>
Maybe I've missed the point but this seems simple enough to me. I've written
macros the way I think you're describing before just like this:
1. Macro definition:
<p metal:define-macro="foo"
tal:define="rhubarb bar | python:[]">
<span tal:repeat="item rhubarb">
stuff
</span>
</p>
'bar' just gets plucked out the current namespace. Or maybe I've missed some
deep and complicated problem here : )
Harry