[Zope] another beginners question about dtml
Michel Pelletier
michel@digicool.com
Fri, 2 Jul 1999 17:42:28 -0400
> -----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> <a
> href=/etf/ee/<!--#var id-->
> style="text-decoration: none" ><font
> color=#ffffff><!--#var title_or_id-->
> </font></a> </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 )
>