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

hans hans@beehive.de
Thu, 21 Mar 2002 13:12:13 +0000


seb bacon wrote:

> On Thu, 2002-03-21 at 11:44, Thomas Olsen wrote:
> > On Thursday 21 March 2002 12:23, you wrote:
> > >   <b tal:condition="exists:currentnamespace/foo">Foo exists</b>
> >
> > Not sure but cant you do:
> >
> > <b tal:condition="exists:foo">Foo exists</b>
>
> Thanks for the pointer, of course you are right.  However, in trying to
> reduce it to a simple example, I phrased my problem completely wrongly.
> I'm trying to set a default value in an expression.  If I test for it
> then I have to branch the code, which I find a bit messy in ZPT.  What
> I'm trying to do is more like:
>
>   <span tal:define="thing python:namespace.get('thing', 'defaultval')">

just yet another pointer: there is something like _.test() in dtml
-------------------------------------------------------------
Who's got only a hammer sees the world as a nail
hans augustin  (software developer)           hans@beehive.de
beehive elektronische medien GmbH       http://www.beehive.de
phone: +49 30 847-82 0                  fax: +49 30 847-82 299