[ZPT] REQUEST argument

Guido van Rossum guido@digicool.com
Sun, 13 May 2001 19:10:15 -0500


> Just to reiterate - the behaviour you implemented is by far the most common
> usage we've seen so far. We have yet to have a situation where we'd want
> the subexpression to be ignored if it returned false. Explicit false values
> are useful :)

This is interesting.  I can't judge this one from practice, since I
haven't written any significant templates (yet -- we're embarking on a
rewrite of python.org that will use PageTemplates).  But Jim Fulton
expressed the strong opinion that, like dtml-if, we should treat
non-existence and emptiness the same.  I'm curious about what makes
PageTemplates different from DTML here.

Apparently (I haven't written much DTML either ;-) in DTML a common
idiom is:

  <dtml-if foo>
    <dtml-var foo>
  </dtml-if>

which substitutes foo only if it exists and is non-empty, and Jim
claims that this is useful.

How would one write DTML that substitutes foo if it exists, regardless
of whether it is empty?

Of course, if it's empty, it doesn't matter much whether the condition
is true of false -- nothing (except some whitespace) gets substituted
anyway.

So maybe that's the crux of the matter: <dtml-if> is really abused to
test for existence, and the fact that it also test for non-emptiness
is not required but neither is it harmful.  Given its name, its
purported primary purpose is to test for non-emptiness, but what makes
it useful in this case is the fact that undefined values are
considered false rather than raising an exception (like they do in
Python).

Using a C preprocessor analogy: DTML has #if but not #ifdef, so we're
making #if do the work of #ifdef -- which usually works.

Since PageTemplates have a different set of primitives, different
forces apply: a|b is used in a context where the existence test is
most needed, while for non-emptiness we can use tal:condition -- which
raises an error on undefined names unless we use a|nothing.

So, do we even need a||b (which requires a to be defined and non-empty)?

--Guido van Rossum (home page: http://www.python.org/~guido/)