You are not logged in Log in Join
You are here: Home » Members » dpetersen » How To use plone folders from navigation slot in ZPT

Log in
Name

Password

 

How To use plone folders from navigation slot in ZPT

 

Created by dpetersen . Last modified 2003-11-01 10:57:11.

This document describes how to fill a index_html page with subfolders from the current directory using plone publishing logic.

Introduction

If you dont want the default plone folder_listing to show subfolders and documents you just can create a static index_html plone document and manually add links from there. But this can be a bit of a hassle to maintain, if your site is very dynamic. Because a folder can have a description property it makes sense to use that description in index_html. There are several ways to access folder id, title and description.

The Zope Way

You can retrieve a list of folders from the current folder like this <div tal:define="subfolders python:here.objectValues(`Plone Folder`);">
and then iterate over it with <div tal:repeat="folder subfolders">.
While this is very easy there is one thing you might not want: It would show folders that are not published yet.

The Plone Way

So we use the Plone internal function navigation_tree_builder to retrieve the same list of subfolders as the navigation slot shows: <div tal:define="tree python:here.navigation_tree_builder(here,showFolderishSiblingsOnly=1,includeTop=0);"> and then iterate: <div tal:repeat="folderobj tree/list"> <span tal:define="folder python:folderobj[`object`];">

If the current folder has a string property folderimage index_html will insert an image at tal:attributes="src string:${here/folderimage}", images/dotimage is a defined constant for a tiny dot that will show up in front of each folder.

Here is the index_html ZPT in full length :

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US"
       lang="en-US"
       metal:use-macro="here/main_template/macros/master"
       i18n:domain="plone">
 <body>
            <!-- ##### define 'listingimage' for folder list below in line 12 -->
 <div metal:fill-slot="main" 
      tal:define="listingimage string:images/dotimage;
                  tree python:here.navigation_tree_builder(here,showFolderishSiblingsOnly=1,includeTop=0);">
     <div class="contentHeader">
         <h1 tal:content="here/title_or_id">Title or id</h1>
     </div>
     <div class="description"
          tal:content="structure here/Description"> description 
     </div>

 <!-- ##### BEGIN CUSTOM CONTENT -------------------------------------------  -->

 <table width="90%" cellspacing="5" border="0">
   <tr> 
     <td width="25%" align="left" valign="top">
       <div tal:condition="exists:here/folderimage">   <!-- ### get 'folderimage' from Folder Properties  -->
         <img src="dummy.img" tal:attributes="src string:${here/folderimage}" width="175" height="175">
       </div>
     </td>
     <td width="5%"> &nbsp; </td>
     <td width="70%" align="left" valign="top"> 
       <b><font size="-1" color="#686667">
         Bitte w&auml;hlen Sie einen Men&uuml;punkt aus oder benutzen Sie die Navigationsleiste
       </font></b><br><br>

     <table width="100%" border="0">
       <div tal:repeat="folderobj tree/list">  <!-- ### BEGIN FOLDER LOOP --- -->
         <span tal:define="folder python:folderobj['object'];"
               tal:on-error="structure string:<!--Error in Navigation loop!!-->">
           <tr><ul> 
             <td width="15" valign="top">
               <img src="dummy.img" tal:attributes="src listingimage" width="10" height="10">
             </td>
             <td valign="top"><a href="folder"
              tal:attributes="href folder/absolute_url"
              tal:content="folder/title">folder title</a>
              &nbsp; <font size="-2"><span tal:replace="folder/description">description</span></font>
             </td>
           </ul></tr>
         </span>
       </div>                                 <!-- ### END FOLDER LOOP ------ -->
     </table>

     </td>
   </tr>
 </table>

 <!-- ##### END CUSTOM CONTENT ---------------------------------------------  -->
 </div>
 </body>
 </html>

Comment

Discussion icon Necessary change for more recent Zope versions (like 2.7.1)

Posted by: tesmer at 2004-07-12

In more recent Zope versions the line

tree python:here.navigation_tree_builder(here,showFolderishSiblingsOnly=1,includeTop=0);">

should be replaced by

tree python:here.plone_utils.createNavigationTreeBuilder(here,showFolderishSiblingsOnly=1,includeTop=0);">

to make the example index_html work.