[Zope] RE: Re[2]: [Zope] comparing variables from different name spaces?

Chris McDonough chris@iqgroup.com
Tue, 28 Sep 1999 13:15:20 -0400


I think you're going the "wrong way" with the "-3".

The PARENTS object is a Python list of object containers, indexed from 0 to
n.  PARENTS[0] is the current container.  PARENTS[1] is the parent container
of the current container.  PARENTS[2] is the parent container of the parent
container of the current container, et. al.

When you say PARENTS[-3], what you're telling Zope you're looking for is the
item third from LAST in the list, which in the case you were in /test would
not exist, and therefore you get the error.  You can check the mailing list
for the hasattr method (function?) to check for existence of an object
without raising an error (I'm not the one to ask, I've only used it once),
if you'd like...

But a better solution to this problem was given by Michel Pelletier in his
answer to your question, which was to use code like this:

<dtml-with test>
  <dtml-if "dir2 in PARENTS">
    dir2 is one of your parents
  </dtml-if>
</dtml-with>

What this does in the expression "dir2 in PARENTS" is say, "iterate over the
PARENTS list, and return true if dir2 is a member of the list".

Am I making any sense?


-----Original Message-----
From: Ainis [mailto:ainis@mindless.com]
Sent: Tuesday, September 28, 1999 11:24 AM
To: Chris McDonough; zope@zope.org
Subject: Re[2]: [Zope] comparing variables from different name spaces?


Hello Chris,

Well, it almost worked. I had to use <dtml-var "PARENTS[-3].id">
but now I have another problem. This variable does not exist when i
make requests in /test/ folder (which is normal, as /test/ has no
such parents), in /test/dir2 it works fine.
So I tried:
<dtml-if "PARENTS[-3].id">
but i get an error if it does not exist. So how do i check if the
variable exists?

Tuesday, Tuesday, September 28, 1999, you wrote:

CM> You can do this by using the PARENTS object.

CM> For example, the following (untested) code, when run from
CM> http://youserver/test/dir2/hardware/prices/index_html (assuming
index_html
CM> is a dtml method and not a dtml document -- a dtml document has its own
CM> properties) will give you the id of the /test/dir2 folder:

CM> <!--#var "PARENTS[2].id"-->

CM> e.g. it will print "dir2"

CM> While:

CM> <!--#var "PARENTS[1].id"--> will give you the id of the hardware folder
CM> (e.g. it will print "hardware"), et. al.

CM> I think this is what you're looking for..



Best regards,
 Ainis                            mailto:ainis@mindless.com