RE: [Zope] comparing variables from different name spaces?
Ainis, You can do this by using the PARENTS object. For example, the following (untested) code, when run from http://youserver/test/dir2/hardware/prices/index_html (assuming index_html is a dtml method and not a dtml document -- a dtml document has its own properties) will give you the id of the /test/dir2 folder: <!--#var "PARENTS[2].id"--> e.g. it will print "dir2" While: <!--#var "PARENTS[1].id"--> will give you the id of the hardware folder (e.g. it will print "hardware"), et. al. I think this is what you're looking for.. -----Original Message----- From: Ainis [mailto:ainis@mindless.com] Sent: Monday, September 27, 1999 6:40 PM To: zope@zope.org Subject: [Zope] comparing variables from different name spaces? Hello ALL, How do i compare variables from two different namespaces? In my current situation I need to check if my current path is in some directory tree. For example lets say I have folders /test/dir1 /test/dir2 /test/dir3 In these folders there are alot more other folders, so when i currently am in for example /test/dir2/hardware/prices/index_html the script should check in which of those 3 root folders (dir1, dir2 or dir3) am i. Now lets look at the part of /test/dir2/hardware/prices/index_html source: <dtml-with test> <dtml-in "objectValues(['Folder'])"> <!--#var id--> </dtml-in--> </dtml-with--> Ok, so in this case i have a loop in which i go through ids of all folders in /test/ but now how do I check test's subfolder's id is PARENT of my current /test/dir2/hardware/prices/ folder? I think the easiest way would be- <dtml-if dir2> but that has to be done only from /test/dir2/hardware/prices/ names pace which (i think) I have already lost with <dtml-with test>. So how do I compare the older name space's variable with newer one's? I also tried some tricks with <dtml-with blah only> but with no success. P.S. excuse me if this turns out to be lame question, I'm a bit new to Zope Best regards, Ainis mailto:ainis@mindless.com _______________________________________________ Zope maillist - Zope@zope.org http://www.zope.org/mailman/listinfo/zope (To receive general Zope announcements, see: http://www.zope.org/mailman/listinfo/zope-announce For developer-specific issues, zope-dev@zope.org - http://www.zope.org/mailman/listinfo/zope-dev )
Is there a way to easily get DTML source for pages? (I'd like the DTML source for a property sheet management page). BTW -- www.zope.org seems to be having problems at the moment? ___________________________________________ Joshua Brauer joshua@brauer.org http://www.brauer.org ___________________________________________
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
Ainis wrote:
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?
From Michel Pelletier:
<dtml-with test> <dtml-if "dir2 in PARENTS"> dir2 is one of your parents </dtml-if> </dtml-with> This will work no matter where dir2 is in the acquisition hierarchy (as long as it's within test). -- ~mindlace
Hello Ethan, Tuesday, Tuesday, September 28, 1999, you wrote: EF> Ainis wrote:
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?
From Michel Pelletier:
EF> <dtml-with test> EF> <dtml-if "dir2 in PARENTS"> EF> dir2 is one of your parents EF> </dtml-if> EF> </dtml-with> EF> This will work no matter where dir2 is in the acquisition hierarchy (as EF> long as it's within test). Yeah, but this is not the answer I was looking for. This checks for any parent and I need to check only for the parent at the root. example: I have folders: /test/blah/qwer/wert/erty/rtyu/ /test/ouch/asdf/sdfg/dfgh/fghj/ so when i execute a script from /test/blah/qwer/wert/erty/rtyu/ i get a list of subfolders in /test/, that's "blah" and "ouch" and then i must determine which one of the two is my parent. Your model would not work in a case when any other parent of the current folder has also id of blah which could happen on my site :) I have partially solved my problem. I'm comparing a list of /test/ subfolders with "PARENTS[-3].id" and it works just fine but thing blows up when I try to execute script from /test/ and it's easy to understand why because in /test/ "PARENTS[-3].id" does not exist. My problem now is only to check if "PARENTS[-3].id" exists but how can I do that? <dtml-if "PARENTS[-3].id"> for some strange reason does not work :( Best regards, Ainis mailto:ainis@mindless.com
Ainis wrote:
I have partially solved my problem. I'm comparing a list of /test/ subfolders with "PARENTS[-3].id" and it works just fine but thing blows up when I try to execute script from /test/ and it's easy to understand why because in /test/ "PARENTS[-3].id" does not exist. My problem now is only to check if "PARENTS[-3].id" exists but how can I do that? <dtml-if "PARENTS[-3].id"> for some strange reason does not work :(
Try: <dtml-if PARENTS[-3]> (you don't care about the ID, just whether it's deep enough, _then_ you want to check for ID) If that doesn't work: <dtml-if "test in PARENTS"> check for dir2 </dtml-if> Which will work in subfolders of test (even if they're test) but not in /test. (I think- if you run this test in a document as opposed to a method, it might not be true.) -- ~mindlace
participants (4)
-
Ainis -
Chris McDonough -
Ethan Fremen -
Joshua Brauer