-----Original Message----- From: Kam Cheung [mailto:zope@littlecircle.com] Sent: Monday, July 12, 1999 9:45 PM To: Zope List Subject: [Zope] Object reference in Zope???
Thanks for everyone who has helped me on this problem. It turned out that there is something wrong with my permission setting.
However, I am still not very clear what is the best way to refer to a subfolder object in Zope.
Here is what I find out so far:
Let's say I have a site like this
Home index_html testing data testing
1) Problem One When I am in index_html, I can refer to Home.testing by doing: <!--#var testing-->
But if I want to display Home.data.testing in index_html, I have to do: <!--#var "data.testing"-->
alternativly you can do: <!--#with data--> <!--#var testing--> <!--#/with-->
NOTE: <!--#var data.testing-->, without the double quote, doesn't cut it. Also, if I want to see Home.testing's title, I have to do <!--#var "testing.title"-->, not <!--#var testing.title-->
To use the python dot (.) operator, you must use an expression because it needs to be evaluated.
Question: What's the reason behind this inconsistency of reference? Given the excellent work the Zope team has shown in the product, I am sure that there must be a reason, right?
This might be a little strange, but it's not inconsistent. The dot operator needs to be evaluated therfore it goes in double quotes. unquoted arguments (referencing by name) is a simpler case for when you just want the object to take care of itself. If you want to be picky about what on the object you want (a certain atribute, calling a method...) you must evaluate it.
2) Problem Two Let's say in index_html, I have a string property called "pageID", and "pageID" equals to the string "testing".
Now, if I want to use the "pageID" to refer to the two "testing" documents, I thought I can do:
<!--#var [pageID]--> or <!--#var "data[pageID]"-->
But they don't work. What I end up doing is: <!--#var "_.getitem(pageID, 1)"-->
That work. The problem is, how can I get "Home.data.testing"? <!--#var "_.getitem(data[pageID], 1)"--> surely won't work,
<!--#with data--> <!--#var "_.getitem(pageID, 1)"--> !--#/with--> I'm not sure, but I believe: <!--#with data--> <!--#var "_[pageID]"--> <!--#/with--> will work. won't take long to find out! ;)
but I am surprised that even if I spell out the full path, it still wouldn't work: <!--#var "_.getitem('data.testing', 1)"--> nor does <!--#var "_.getitem(data.testing, 1)"-->
getitem cannot resolve objects through the dot operator. it expects a string which it uses to find an attribute by the same name, it cannot find attributes of attributes.
What I end up doing is: <!--#with data--> <!--#var "_.getitem(pageID, 1)"--> <!--#/with-->
exactly.
Question: What is the preferred to do that? Is there a better method? Why can't I simply refer to an object inside "_.getitem" using a format like "xxx.yyy"?
That's just the way getitem works, this is how it comes from Python. It's actually quite consistent. -Michel