[Zope] simple var

Paul Zwarts paz@oratrix.com
Fri, 14 Jun 2002 21:14:21 +0200


Hi all,

Thanks Oleg and Jim for your responses. And also Max, on a previous
thread. Although the comments are enlightening, I still don't understand
a way that I can get to my solution. 

What I need to do is be able to pull a document from the root of my site
based on a variable. This variable could by several levels deep, it
doesn't matter. The best of it is that I need to render several many
objects that may reside at each level I traverse from the root.

Level1 /
         RenderIndex
         Level2 /
                  RenderIndex
                  Level2

As a solution I tried the following:

<dtml-var "_[sName'].index_html">

Based on responses from Jim and Oleg, this doesn't work past the first
iteration ('something'.index_html) because anything that is
something.something is really rendered as 'something.something' rather
than 'something' . 'something'... if you catch my drift. A string is
really a very literal thing in python, and you have to do really nasty
things to convince it otherwise...

<dtml-in "listWithSeveralItems">
 <dtml-with sequence-item>
   <dtml-var index>
 </dtml-with>
</dtml-in>

The above doesn't work either because you iterate over values within the
current context rather than ascending one level each iteration which is
desired. What I need to be able to do is set the current namespace by a
loop, call some things within that namespace, and then iterate up again
to the next namespace and repeat. 

Either python or dtml, I still don't see how I can get there.....

Sorry for the continued hassles,
Paz


-----Original Message-----
From: zope-admin@zope.org [mailto:zope-admin@zope.org] On Behalf Of Jim
Penny
Sent: Friday, June 14, 2002 4:42 PM
To: Paz; zope@zope.org
Subject: Re: [Zope] simple var

On Fri, Jun 14, 2002 at 02:08:58PM +0200, Paz wrote:
> I'm sorry to have to post this request, but I'm lost behind python
> syntax again.
> 
> This works:
> 
> <dtml-with "folder1.folder2"><dtml-var index_html></dtml-with>
> 
> This doesn't:
>    <dtml-call "REQUEST.set('sName', 'folder1.folder2')">
>    <dtml-with "_[sName]"><dtml-var index_html></dtml-with>

To expand on Oleg's remark in a different way --

_[sName] asks for the contents in the _ namespace of the item
whose name is given by the variable sName.

You wanted _['sName'], which is the contents in the _ namespace
of the item named 'sName'.

Note the extra level of dereferencing.  90% of the time, when you
are working with a dictionary, you want dict['someName'].  And the
other 10% of the time, you have to be sure that if you use
dict[someVariable], that variable has been assigned a valid name
of an item in the dictionary.  [Technically, this language is not
quite right, I should be talking of keys and values, 
(rather than variables and contents), but I think
the way I have said it will be easier to wrap your mind around.]

On the other hand, it would not have worked anyway, per Oleg's
explanation.

Jim Penny
> 
> Nor does:
>    <dtml-with "_.getitem(sName)"><dtml-var index_html></dtml-with>
> 
> What am I missing?
> 
> Thanks,
> Paz
> 
> 
> 
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - 
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
> 


_______________________________________________
Zope maillist  -  Zope@zope.org
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )