DTML Basics (part 4) - Climbing A Tree (Page 5 of 9 )
One of the most striking features of the Zope Management Interface is the navigation menu that appears on the left side. And the cool thing is, Zope comes with a built-in construct that allows you to replicate and use this tree structure for your own purposes. It's called the <dtml-tree> tag - and here's what it looks like:
<dtml-tree>
<dtml-var getId>
</dtml-tree>
This is a very simple implementation of the <dtml-tree> tag...as you can see
from the output below:

Here, the <dtml-tree> tag dynamically searches for the objects in the current folder and lists them by ID. It is obvious that, by default, it lists only the folders in the current location.
Now, let me make the example more interesting:
<dtml-tree branches_expr="objectValues()" sort=id>
<dtml-var getId>
</dtml-tree>
Here's the output:

I now have a listing of all the objects in the current folder along with a neat little icon that allows downward traversal. Give it a shot and you'll see that you can now see all the objects under the current folder.
<dtml-tree branches_expr="objectValues()" sort="id">
The additional "branch_expr" attribute of the <dtml-tree> tag is used to specify
the expression that will be evaluated by Zope to display the listing of the objects in the tree. The "sort" attribute tells Zope to sort the list by ID.
Want to play around with the code shown above? Just add the "reverse" attribute:
<dtml-tree branches_expr="objectValues()" sort="id" reverse>
Here's a brief list of the most useful <dtml-tree> attributes - try them at your leisure:
"header" - this allows you to specify a DTML document that will be displayed as a header for each expanded node.
"footer" - this is similar to the "header" attribute explained above, as it allows you to specify the footer for each expanded note.
"nowrap" - set this to true if you want to truncate the nodes if there isn't enough space to expand them.
Next: The Real Thing >>
More Zope Articles
More By Harish Kamath, (c) Melonfire