[Zope] looping over plone folders

J. Cameron Cooper jccooper at jcameroncooper.com
Thu Sep 25 00:45:28 EDT 2003


>Another newbie-ish question, looked in the FAQ but couldn't find an
>example that was clear enough...
>
>I'm recreating the navbar in a plone portal by hand, looping over the
>plone folders in the root folder of the plone site.  Ok, that's what I
>*want* to do, and need help from a zenmaster on how to do it within
>plone  :^)  The reason for this is that I'd like it to be
>dynamically-generated, based on the folders created; and hope to have a
>javascript-based dynamic menu populated by the objects within those root
>folders.  So far, when I use examples of looping (via ZPT
>documentation), Plone throws a security error and refuses to cooperate.
>
>So I suppose the two questions are:
>
>1) How do you do this in Plone?
>
>2) Is there a better approach?
>  
>
Easy: create a ZPT in your skins folder (probably 'custom') named 
'recurse'::

<ul>
<li tal:repeat="item here/objectValues">
  <span tal:content="item/getId" tal:omit-tag="">An object</span> :
  <span tal:content="item/title" tal:omit-tag="">A title</span>
  <span tal:condition="python:item.meta_type=='Folder'" 
tal:content="structure item/recurse">A Folder listing</span>
</li>
</ul>

Include this wherever you want, like in your header skin or in another 
ZPT that you can use as a slot like the NavTree (since you're using 
Plone.) You'll have to learn a little ZPT, of course, but it isn't so bad.

The condition check is pretty primitive. Probably a better one would 
check for the presence of the objectValues method like

tal:define="folderish nocall:item/objectValues"
tal:condition="folderish | nothing"

You could also check the CMF type of the object to only display Folders, 
etc. You can also of course condition the 'leaf' display to only display 
folders as well (since this code does a full site tree.)

This will construct a nested HTML unordered list of your tree from the 
place where you called it (from inside a valid HTML page.) You can of 
course tweak the display code: I think you can see how you would use 
this to populate the data structure of whatever dynamic menus you're using.

Consider using pure CSS menus rather than Javascript:
http://www.meyerweb.com/eric/css/edge/menus/demo.html

There are also products that will create site maps which you might be 
able to modify. Search around.

       --jcc

-- 
"My point and period will be throughly wrought,
Or well or ill, as this day's battle's fought."





More information about the Zope mailing list