[Zope] dtml docs, methods and trees, newbie qs

Chris Withers chrisw@nipltd.com
Mon, 28 Feb 2000 17:57:16 +0000


Hi,

This got me at first too, it really should be better documented...

> It seems that if I put the simplest dtml-tree
> 
> <dtml-tree>
> <dtml-var id>
> <dtml-tree>
> 
> in a dtml method it works ok.  If i put it in
> a dtml doc it doesn't.  If I put it in a method

> 3. What is the most important piece of understanding
> I am missing to figure out answers to these q's.

Answering this should cure the others. I think (and I'm sure other will correct
me if I'm wrong... ;-) that dtml-method's have no namespace, and so use their
parent's, while dtml-documents have a namespace and so don't.

This means that dtml-tree will work as-is on both documents and methods, except
documents won't generally return anything because they never have any children.
dtml-methods, however, use their parent's (usually a folder) name space and so
all the children of the parent folder are returned.

To get around this, you need to use the PARENTS variable, which is a python list
of parent objects for your current object. PARENTS[0] is the parent of the
current object (bear in mind that PARENTS[0] in a dtml-method will return the
parent of the FOLDER CONTAINING the dtml-method for reasons already described)

Finally, only folders seem to implement the tpValues method which is the default
used to find branches below an object, so you'll need to replace it with the
objectValues method which seems to return all children of the current object.

Putting this all together, we have:
<dtml-tree expr="PARENTS[0]" branches=objectValues>
 <dtml-var id>
<dtml-tree>

which will probably return what you were expecting...

Welcome to Zope, the exits to your left and right are clearly marked by the Zope
DTML Guide and the Mailing List Archive Search Mechanism ;-)

cheers

Chris