[Zope] testing with dtml-if

Dylan Reinhardt zope at dylanreinhardt.com
Fri Sep 5 19:22:02 EDT 2003


On Fri, 2003-09-05 at 10:52, garry saddington wrote:
> <dtml-if w>  does what it should do

If "what it should do" means "testing the existence *and* truth of w".  

If w is *any* non-False value such as 1, 2, 'hello world', or
['a','b','c'] this test will evaluate True.  If w is 0, [], None, or
doesn't exist, it will evaluate False.  If those results are what you
want, cool.

> but what you suggest does not work nor do any of the other combinations i have 
> tried. I can demostrate that w=1 by displaying <dtml-var w>.

Or maybe what you've demonstrated is that w is equal to '1', which is
going to render the same on-screen but is not the same data.  If w is a
variable you're grabbing from a form, that's the case almost for
certain.

You're far better off writing your tests for the *exact* condition
you're testing, rather than using a broad existence/truth test and
assuming the rest.   If the test "w==1" does not return True, then w is
not equal to 1.  Maybe it's equal to something that looks like 1, but
this is not the same thing.

HTH,

Dylan





More information about the Zope mailing list