tree tag global navigation
Fellow Zopesters, Here is a short tutorial on using the tree tag for global navigation in your site. Step 1: Create an external method with the following code: def getFoldersOnly(self): """Return a list of only the Folders contained in an object, for use by the tree tag""" return self.objectValues(['Folder']) This is neccesary in order to avoid listing the product and acl_users folder objects. Thanks to Kent Polk for the code. Modify this code if you want to display something other than just folders, For example: Step 2: Create a DTML method named SideBar in your root folder with the following code: <!--#tree branches=getFoldersOnly--> <A HREF="<!--#var BASE1-->/<!--#var tree-item-url-->"><!--#var id--></A> <!--#/tree--> Notice that we are generating absolute URL's. Thanks to Kent Polk and Martijn Pieters for this code. Step 3: Call SideBar with the following code from anywhere in your site using this code: <!--#var "SideBar(PARENTS[-1],REQUEST)"--> And voila! it should display a tree of your entire site structure! Thanks to Amos Latteier for this deceptively simple code snippet. I hope this helps others who may have been struggling with this. Michael Bernstein
At 19:48 23-2-99 , Michael Bernstein wrote:
Step 1: Create an external method with the following code:
def getFoldersOnly(self): """Return a list of only the Folders contained in an object, for use by the tree tag""" return self.objectValues(['Folder'])
This is neccesary in order to avoid listing the product and acl_users folder objects. Thanks to Kent Polk for the code. Modify this code if you want to display something other than just folders, For example:
Step 2: Create a DTML method named SideBar in your root folder with the following code:
<!--#tree branches=getFoldersOnly--> <A HREF="<!--#var BASE1-->/<!--#var tree-item-url-->"><!--#var id--></A> <!--#/tree-->
You can skip the External Method if you use the branches_expr tag, instead of the branches tag, like so: <!--#tree branches_expr="objectValues(['Folder'])"--> <A HREF="<!--#var BASE1-->/<!--#var tree-item-url-->"><!--#var id--></A> <!--#/tree--> See my emails on Tree tag options... (somewhat muddied by the absence of sleep when I wrote it.... attributes that are listed as =[0|1] don't need an argument, like <!--#tree assume_children-->) See: http://www.zope.org/pipermail/zope/1999-February/001747.html and http://www.zope.org/pipermail/zope/1999-February/001749.html
Step 3: Call SideBar with the following code from anywhere in your site using this code:
<!--#var "SideBar(PARENTS[-1],REQUEST)"-->
This is a very neat snippet of code. I like the PARENTS[-1] trick.
Martijn Pieters wrote:
Step 2: Create a DTML method named SideBar in your root folder with the following code:
<!--#tree branches=getFoldersOnly--> <A HREF="<!--#var BASE1-->/<!--#var tree-item-url-->"><!--#var id--></A> <!--#/tree-->
You can skip the External Method if you use the branches_expr tag, instead of the branches tag, like so: <!--#tree branches_expr="objectValues(['Folder'])"--> <A HREF="<!--#var BASE1-->/<!--#var tree-item-url-->"><!--#var id--></A> <!--#/tree-->
Is there a performance difference between these two approaches? If not, I think I would prefer to factor out the method, as it might come in handy somewhere else. Michael Bernstein
At 01:36 25-2-99 , Michael Bernstein wrote:
Martijn Pieters wrote:
Step 2: Create a DTML method named SideBar in your root folder with the following code:
<!--#tree branches=getFoldersOnly--> <A HREF="<!--#var BASE1-->/<!--#var tree-item-url-->"><!--#var id--></A> <!--#/tree-->
You can skip the External Method if you use the branches_expr tag, instead of the branches tag, like so: <!--#tree branches_expr="objectValues(['Folder'])"--> <A HREF="<!--#var BASE1-->/<!--#var tree-item-url-->"><!--#var id--></A> <!--#/tree-->
Is there a performance difference between these two approaches? If not, I think I would prefer to factor out the method, as it might come in handy somewhere else.
Michael Bernstein
I think the latter version, branches_expr, would be faster, but only by a merest sliver of a fraction. The external method is after all another stack level. Using the branches expression skips a step. Compare EM: branches -> external method -> tree-list-expression Direct: branches_expr -> tree-list-expression
Michael, thanks for the tutorial! There is a lot of territory to cover in Zope (as a zope newbie i know that only too well), and incisive tips like your can make the whole process a lot more manageable. In that light, i've started to collect decently cooked tips like yours, at: http://www.zope.org/Community/Services/ I do not reliably follow all the traffic on the newsgroup (i'll have a bit more to say about that in a subsequent post), so if you produce or see a particularly revealing tip, contact me directly about it, and i'll see about including it in the batch. Ken Manheimer klm@digicool.com Michael Bernstein wrote:
Fellow Zopesters,
Here is a short tutorial on using the tree tag for global navigation in your site.
At 10:48 AM 2/23/99 -0800, Michael Bernstein wrote:
Fellow Zopesters,
Here is a short tutorial on using the tree tag for global navigation in your site.
Thank you Michael! This is a wonderful contribution and I would like to put it up on the Zope site as a How-To.
Step 1: Create an external method with the following code:
def getFoldersOnly(self): """Return a list of only the Folders contained in an object, for use by the tree tag""" return self.objectValues(['Folder'])
This is neccesary in order to avoid listing the product and acl_users folder objects. Thanks to Kent Polk for the code. Modify this code if you want to display something other than just folders, For example:
As was mentioned, this can be accomplished in DTML directly, no need for an external method.
Step 2: Create a DTML method named SideBar in your root folder with the following code:
<!--#tree branches=getFoldersOnly--> <A HREF="<!--#var BASE1-->/<!--#var tree-item-url-->"><!--#var id--></A> <!--#/tree-->
Notice that we are generating absolute URL's. Thanks to Kent Polk and Martijn Pieters for this code.
Step 3: Call SideBar with the following code from anywhere in your site using this code:
<!--#var "SideBar(PARENTS[-1],REQUEST)"-->
And voila! it should display a tree of your entire site structure! Thanks to Amos Latteier for this deceptively simple code snippet.
participants (4)
-
Amos Latteier -
Ken Manheimer -
Martijn Pieters -
Michael Bernstein