[Zope] Recursive method

Michel Pelletier michel@digicool.com
Fri, 20 Aug 1999 21:22:24 -0400


Roché Compaan wrote:
> 
> I want to use a recursive method do draw the navigation tree for my site.  I
> do not want to use the tree tag to iterate through the subfolders because
> the question-mark in the tree-query might obscure pages of the site to
> search engines.  How can one call a method from within a method passing
> variables to that method?  How does one define a method which accepts
> certain parameters eg.
> 
> if someone can translate this in to dtml for me this would be a great help:
> 
> recursive-dmtl-method(variable folder)
>   in folder
>     if document then
>        makeHREF to document
> 
>   if folder.hassubfolders then
>      recursive-dtml-method(folder)
> --------------------------------------
> 
> This would be of great help.
> 


Here is a similar question I answered several weeks ago:



> Subject: 
>          RE: [Zope] another beginners question about dtml
>     Date: 
>          Fri, 2 Jul 1999 17:42:28 -0400
>    From: 
>          Michel Pelletier <michel@digicool.com>
>      To: 
>          "'Lauri Posti'" <lauri@linnet.ee>, zope@zope.org
> 
> 
> 
> 
> 
> > -----Original Message-----
> > From: Lauri Posti [mailto:lauri@linnet.ee]
> > Sent: Friday, July 02, 1999 3:53 PM
> > To: zope@zope.org
> > Subject: [Zope] another beginners question about dtml
> > 
> > 
> > hi,
> > 
> > the question is: 
> > how to determine the number of elements in list?
> > in my case nubmer of elements in PARENTS[] .
> > 
> 
> <!--#var "_.len(PARENTS}"-->
> 
> > the problem is:
> > create list of subfolder of folder and it subfolders if there 
> > are some.
> > 
> > or can anyone give better solution than using PARENTS?
> > the current code is:
> 
> Create a method that lists the subfolders in this folder, and, if there
> is a method of a certain name in a subfolder, call it.
> 
> The trick is, the 'method of a certain name' is the SAME method as the
> one you create.  This is an extremely tricky acquisition/recursion
> trick.  To do this trick, create two DTML methods in your top level
> folder, 'start' and 'voodoo'.
> 
> DTML Method 'start':
> 
> <!--#var standard_html_header-->
>   <!--#var voodoo-->
> <!--#var standard_html_footer-->
> 
> DTML Method 'voodoo':
> 
> <!--#in "objectValues('Folder')"-->
>   <!--#var id--> 
>   <a href="<!--#var absolute_url-->"><!--#var absolute_url--></a><br>
>   <!--#var voodoo--><br>
> <!--#/in-->
> 
> 
> Notice that the voodoo method calls itself.  Thus, the voodoo method
> will call the voodoo method in every subfolder it finds, which in turn
> calls the voodoo method on it's subfolders.... etc. until 'objectValues'
> returns no more subfolders.  Classic recursion.
> 
> Where the voodoo comes in is that the method 'voodoo' does NOT have to
> be in every single folder on the site.  All of the subfolders, and their
> subfolders, *acquire* the method from 'above' them.  Thus, recursion and
> acquisition are used together, one to travel down the objects to
> recursivly call itself, the other to travel up to objects to find itself
> so it can call itself recursively, and when you mix the two together,
> you get a much simpler solution (but not a very gramaticaly sane
> sentence, try it, it will work for you).
> 
> Welcome to the Zen of Zope. ;)
> 
> -Michel
> 
> 
> > 
> > <!--#in "PARENTS[-3].objectValues(['Folder'])"-->
> >           <td 
> >    <!--#if "PARENTS[-4].id==id"-->
> >           bgcolor=#034F6B
> >    <!--#/if-->
> >           nowrap=1 width=7% align=center valign=center><b>
> >       <font face="helvetica" size=2>&nbsp;<a 
> > href=/etf/ee/<!--#var id-->
> >          style="text-decoration: none" ><font 
> > color=#ffffff><!--#var title_or_id-->
> >         </font></a>&nbsp;</font></b></td>
> > <!--#/in-->
> > 
> > 
> > thanks,
> > 
> > Lauri Posti
> > 
> > 
> > _______________________________________________
> > Zope maillist  -  Zope@zope.org
> > http://www.zope.org/mailman/listinfo/zope
> > 
> > (For developer-specific issues, use the companion list,
> > zope-dev@zope.org - http://www.zope.org/mailman/listinfo/zope-dev )
> > 
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://www.zope.org/mailman/listinfo/zope
> 
> (For developer-specific issues, use the companion list,
> zope-dev@zope.org - http://www.zope.org/mailman/listinfo/zope-dev )
> 







> Roché
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://www.zope.org/mailman/listinfo/zope
> 
> (To receive general Zope announcements, see:
> http://www.zope.org/mailman/listinfo/zope-announce
> 
> For developer-specific issues, zope-dev@zope.org -
> http://www.zope.org/mailman/listinfo/zope-dev )