[Zope] URLs, objects, and <dtml-
Dennis Allison
allison@sumeru.stanford.EDU
Wed, 10 Jul 2002 13:20:23 -0700
I am pretty sure there are some clever techniques I have missed.
When I first started using Zope accessing objects at different places in
the object hiearchy was a problem. I found some workarounds and learned
to cope, but I am now revisiting the issue.
For specificity, consider the following folder hiearchy:
R
A1
B1
D1
C1
A2
B2
C2
D2
URLs would reference the somepage object in D2 using the
URL R/A2/C2/D2/somepage.
Now, DTML, for example, <dtml-var >, specifies an object which is located
the current namespace by one of a variety of rules including acqusition.
Control over the namespace is provided using <dtml-with> but using it can
be cumbersome. To reference an object in the folder D2 from D1 would
require wrapping the referencing <dtml-var> in a next of <dtml-with>
statements which make the namespace of A2, C2, and D2 available. For a
site with a deep and complicated hiearchy, this is a mess. Hard to write,
hard to maintain, and very error prone. The tendancy is to make all
scripts look like central mechanism wrapped in multiple with's to setup
the right namespace.
A better approach might be to access all nonlocal objects through a Python
Script that traverses a URL parameter and returns the specified object.
In this case, referencing the object foo in D2 above would be accomplished
by
<dtml-var name="traverse_to_object('R/A2/C2/D2/foo')">
and so forth.
This should work, but it kneecaps Zopes namespace management features because
it returns an object, not a name to be resolved to an object in context through
bobo_traverse, acqusition, and so forth.
So, finally, the question: How does one manage in an efficient and
compact fashion accesses to objects stored outside of the acquisition
path?
There are a couple of other notational issues that are a bit confusing.
If I have a folder (call it scripts) at my site root, I can reference
the individual scripts by the names 'scripts.script1()'. When does
this notation extend to objects stored in nested folders?
One the defining notions of Zope is the equivalence of a page as specified
by a URL and an object. What's the reason that something like
<dtml-var name="R/A2/C2/D2/foo">
does not resolve to the name foo in the container reachable by traversing
"R/A2/C2/D2" when accessed from within Zope. It does work from the Web.
-dra