[Zope] Quick question about <dtml-if ...>

hans hans@beehive.de
Wed, 08 May 2002 16:00:27 +0100


"George M. Ellenburg" wrote:

> On Wednesday 08 May 2002 08:19 am, Gilles Durys wrote:
> >
> > You should use this:
> > <dtml-if expr=3D"a=3D=3D'3'">
> >    <!-- blablabla -->
> > </dtml-if>
> >
> > a=3D=3D'3' test is a equals '3' (I think form values are always strin=
gs -
> > not sure though)

not always. you may type form variables, and ZPublisher converts them for=
 you
see
http://www.zope.org/Members/Zen/howto/FormVariableTypes
http://www.zope.org/Members/hawkfish/radio_records

>
> > a=3D3 assigns the value 3 to a
>
> On Wednesday 08 May 2002 09:19 am, hans wrote:
> >
> > it took me some time to understand, but basically there are 2
> > different ways for name resolution. name=3D... is DTML searching,
> > expr=3D"..." is python searching (everything in " " is python).
> > a name-attribute may consist only of one identifier (thats why syntax
> > error!) (in <dtml-if name=3Dmyid>, nonexistence is treated as falseho=
od).
>
> On Wednesday 08 May 2002 08:22 am, Geir B=E6kholt wrote:
> >
> > <dtml-if "tip =3D=3D 1">
> > .. or even clearer :
> > <dtml-if expr=3D"tip =3D=3D 1">
> >
> > eveluations like this have to be done as python expressions , hence
> > the quotes (they are really just a shorthand for expr=3D"" , and have
> > served to confuse many a newbie....)
>
> Okay,
>
> So if I understand this correctly, even though the expr is called, and =
it's
> evaluating outside the scope of the website, will Python then eventuall=
y
> evaluate it *in* the scope of the website (through acquisition or inher=
itence
> or whatever?)
>
> Sorry, I'm *so* not an OO programmer. ;-)
>
> Wouldn't (or couldn't) there be a name-collision if I'm passing a varia=
ble/
> constant that's already defined (or reserved)?

again:
<dtml-var name=3D"theName">: the DTML-interpreter looks up theName
in the namespace. If it exists, AND is callable, it calls it and replaces=
 w the
result thereof.
nonexistence raises exception.

<dtml-var theName> is a shorthand.
<dtml-if theName>: nonexistence is falsehood.

<dtml-var expr=3D"any-python-expression">:
The DTML-interpreter lets (restricted) python evaluate this (giving pytho=
n also
the namespace)
<dtml-var "theName"> shorthand for expr=3D"theName"
if theName is callable, it will not be called!
<dtml-if "theName">: nonexistence is error
-------------------------------------------------------------
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