[Zope] PARENTS and the with tag

Alice Gutman aliceg@rescomp.berkeley.edu
Mon, 8 Nov 1999 15:24:53 -0800 (PST)


Thanks for explanation.  Here's what I'm trying to do.  I need to generate
a table of contents that uses relative links.  I'm doing the TOC
recursively with a method called dtml_tree, and it works fine except for
the relative links.

So I want to write a method named relative_url that returns the url
relative to the page that initially called dtml_tree.  To do this, I need
to access PARENTS for both the current object and the original
object.  There must be some way to do that, right?

Here's the code for dtml_tree:
<dtml-if "level<0">
<b><dtml-var title></b><br>
<dtml-else>
<dtml-in "_.range(level)">
&nbsp;&nbsp;
</dtml-in>
<dtml-if "id!=calledFrom.id">
<a href="<dtml-var relative_url>"><dtml-var title_or_id></a><br>
<dtml-else>
&gt;<dtml-var title_or_id>&lt;<br>
</dtml-if>
</dtml-if>
<dtml-in "objectItems(['Folder'])">
<dtml-with sequence-item>
<dtml-with "_.namespace(level=level+1)">
<dtml-var dtml_tree>
</dtml-with>
</dtml-with>
</dtml-in>

And I call it from the standard header like this:
<dtml-if "aq_parent.id!='root'">
<dtml-with "_.namespace(calledFrom=aq_parent, level=-1)">
<dtml-with "PARENTS[-3]">
<dtml-var dtml_tree>
</dtml-with>
</dtml-with>
</dtml-if>

Thanks again,
Alice


On Mon, 8 Nov 1999, Rik Hoekstra wrote:

> 
> > Hi,
> >
> > I'm having some scoping issues with PARENTS.  It doesn't seem to
> > acknowledge with tags or anything else.  For example, if I have the
> > folder hierarchy:
> > A
> >   B
> >     C
> >   D
> >     E
> >
> > and in the index_html document of C I say:
> > <dtml-with E>
> > <dtml-in PARENTS>
> > <dtml-var "_['sequence-item'].id"><br>
> > </dtml-in>
> > </dtml-with>
> >
> > it produces:
> > C
> > B
> > A
> 
> That's because acquisition produces a namespace stack of A B C, so in
> reversed order PARENTS are BA if index_html is a DTML Method. If index_html
> is a DTML Document then PARENTS are CBA. Actually Zope should give a
> NameError if you call <dtml-with E>, as E per se is not accessible from C.
> If you want E, you should call <dtml-with "D.E">.
> So. if you call D.E from C's index_html then its PARENTS are still C, B, and
> A. The with tag does not seem to stack namespace upon the existing namespace
> stack.
> 
> >
> > when I actually want:
> > E
> > D
> > A
> >
> > And if I say:
> > <dtml-var "E.PARENTS">
> >
> > then I get an error message.
> 
> Yes, because PARENTS is not an attribute of E. It will generate an error
> anywhere.
> 
> >
> > What am I doing wrong?  Is there an easy way to make it behave like I want
> > it to?
> 
> This is a bit difficult to answer if you do not make clear what you want to
> attain? You could change the folder hierarchy to
> 
> A
>   D
>     E
>       B
>        C
> 
> or in your own hierarchy call C's index html from E.
> 
> Rik
> 
>