Apologies if these are oft-asked q's but I can't find an obvious answer anywhere in the docs. 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 then refer to that in a doc (with <dtml-var> that doesn't work either. Therefore if I want to use a tree I have to use a method. Is that correct? This brings up several q's. 1. How can I call a method and have it do its stuff from a doc? Tried evey which way but I can't get a tree to work by doing this. 2. Since I can't find anything I can't do with a method why have docs at all? 3. What is the most important piece of understanding I am missing to figure out answers to9 these q's. Andy ------------------------------------------------- Andy Heath a.k.heath@open.ac.uk The Open University +44 (0) 114 2885738
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
participants (2)
-
Andy Heath -
Chris Withers