[ZPT] Possible changes to path-related

Evan Simpson evan@digicool.com
Tue, 1 May 2001 18:09:18 -0500


From: "R. David Murray " <bitz@bitdance.com>
> (use-if-exists-and-true) ?

Eeek!

> > tal:action="path:(exists) foo"
> > action(exists('foo'))
>
> So 'action' knows not to do anything if exists returns "some special
flag",
> right?

No, exists returns true if the path exists, and false if it doesn't.
Under no circumstances does it cancel the action.  It is a pure boolean
test, intended for use in tal:condition, although it could certainly
also be used to control a boolean attribute such as "checked".

> > tal:action="path:(if exists) foo"
> > if exists('foo'):
> >     action(foo)
>
> Shouldn't this read:
>
> if exists('foo') and foo:
> action(foo)

Well, I don't know about "shouldn't".  It corresponds accurately to the
current implementation.  Whether the implementation ought to behave this
way is another question.

I'm trying to cover four use-cases, here, each of which corresponds to
some idiom that I expect to be fairly common:

1. Use the path value directly.  Its existence is taken for granted, so
failing to exist is an error.

2. Test the existence of the path.  The canonical case here is
tal:condition="path:(exists)a/b/c", where the statement tag contents
only make sense if 'a/b/c' exists.

3. Use the path value if it is true, otherwise leave the default in
place.  The path's existence is taken for granted (a ZClass property,
for instance), so failing to exist is an error.

4. Use the path value directly, but leave the default in place if the
path doesn't exist.  The canonical case here is tal:replace="path:(if
exists) request/foo", which replaces the tag even if the submitted text
is blank or leaves the default value in place if the request did not
contain 'foo'.

Cheers,

Evan @ digicool