[Zope] Two newbie questions

Kevin Dangoor kid@kendermedia.com
Mon, 6 Sep 1999 22:33:25 -0400


Hi,

  Welcome to Zope :)

-----Original Message-----
From: Chris Fassnacht <cfassnacht@ssc.wisc.edu>
To: zope@zope.org <zope@zope.org>
Date: Monday, September 06, 1999 6:16 PM
Subject: [Zope] Two newbie questions


>1. Object reference across hierarchies.
>
>If I have a folder structure like this:
>
>          A
>       /      \
>     B        C
>    / \       /  \
>  D   E   F    G
>
>Then I can reference an object in A, B, or D from A, B, or D using
<dtml-var
>objectid>.  But if I try to reference something in G from B, for instance,
I
>get a Zope error.
>
>I'm not fully up to speed on the idea of namespaces, but I get the feeling
>that this is the source of my problems.  Unfortunately, I'm not sure how
>force a reference to something in a different namespace using only its
>object id (that is, without having to reproduce the full url path).  Could
>someone enlighten me?

In Zope, the term "acquisition" is used to refer to objects being "acquired"
from higher up in the hierarchy. An object in G can access anything in A
directly by object ID, as can something in D. To get to G from B, you would
need to do something like this:

<dtml-comment>Let's start at the root</dtml-comment>
<dtml-with "PARENTS[-1]">
<dtml-with C>
<dtml-with G>
<dtml-var some_property>
</dtml-with>
</dtml-with>
</dtml-with>

Note that you can also do this in many circumstances:

<dtml-var "PARENTS[-1].C.G.some_property">

>2. Looping a lines property
>
>I've been trying to use the <dtml-in> loop structure to go through the
entry
>in an custom ZClass object's lines property.  But I'm not sure of the
syntax
>(I've looked through most of the documentation and can't find more than a
>minimal description on pg. 44 of the Zope Conten Manager's Guide), and what
>I've tried so far isn't working.
>
>I can access individual line items using <dtml-var "objectid.linesid[n]">,
>but was hoping to avoid having to create an increment variable for n, test,
>increment, etc., since the <dtml-in> structure looked so slick.
>
>What I'm trying to do is to maintain a list of object ids in an object's
>lines property and then generate links (<a href=>'s) from the list.  So, I
>could also use some direction in using the referenced object id in the
lines
>property to access its properties (title, mostly).

<!--untested-->
<dtml-in linesid>
<a href="&dtml-sequence-item;"><dtml-var
"_[_['sequence-item']].title"></a><br>
</dtml-in>
(If &dtml-sequence-item; doesn't work, just do <dtml-var sequence-item>)

sequence-item will contain each of the lines in turn. If you do
_['sequence-item'], you will get the value of sequence-item (ie, the object
id). If you do, _[_['sequence-item']], it will look that objectid up in the
namespace.

Kevin