Personal tools
You are here: Home Tips and Tricks (old) Folder Listing as a Plone Portlet Mini-HOWTO
Document Actions

Folder Listing as a Plone Portlet Mini-HOWTO

by xenophon — last modified 2005-09-15 19:20

How to create a box that displays the contents of a folder using Zope page templates and the Plone 'portlet' macro package.

This folder listing portlet displays the title of the folder, its description, and a list of each item in the folder. Mousing over each link pops up its description in browsers that understand the title anchor (A) tag attribute.

  1. Log into Plone using an account that has the Manager role.
  2. From the Plone Control Panel (the Plone Setup link underneath the search box), access the Zope Management Interface.
  3. Click on portal_skins.
  4. Click on custom.
  5. From the Select type to add drop-down box, choose Page Template and click Add.
  6. When prompted, set the ID of the new page template to portlet_folder_contents and click Add and Edit.
  7. Paste the following code into the text area presented on the Edit screen, then click Save Changes:
    <html xmlns:tal="http://xml.zope.org/namespaces/tal"
          xmlns:metal="http://xml.zope.org/namespaces/metal"
          i18n:domain="plone">
    
    <body>
    
    <!-- A folder's contents as a Box -->
    
    <div metal:define-macro="portlet"
         tal:omit-tag="">
    
    <div class="portlet"
         id="portlet-folder-contents">
    
    <h5 tal:content="here/title_or_id">Folder Name</h5>
    
    <div class="portletBody">
    
    <div class="portletContent odd"
         tal:content="here/description">
    Folder description
    </div>
    
    <div tal:repeat="item here/objectValues"
         tal:omit-tag="">
    
    <div class="portletContent odd"
         tal:condition="repeat/item/odd">
    <a href="#odd"
       title="Odd item description"
       tal:content="item/title_or_id"
       tal:attributes="href item/absolute_url;
                       title item/description">Odd item title</a>
    </div>
    
    <div class="portletContent even"
         tal:condition="repeat/item/even">
    <a href="#even"
       title="Even item description"
       tal:content="item/title_or_id"
       tal:attributes="href item/absolute_url;
                       title item/description">Even item title</a>
    </div>
    
    </div> <!-- tal:repeat="item here/objectValues" -->
    
    </div> <!-- class="portletBody" -->
    
    </div> <!-- class="portlet" -->
    
    </div> <!-- metal:define-macro="portlet" -->
    
    </body>
    
    </html>
    
  8. Test the portlet by clicking Test. This should return a listing of the portal_skins/custom folder.
  9. Use the portlet by adding it to the portal's left_slots or right_slots property. For example, to display the contents of the Plone Members folder, add portal/Members/portlet_folder_contents.
  10. To create a version of the portlet that only displays the folder contents box if a user has logged in, change the lines containing
    <div class="portlet"
         id="portlet-folder-contents">
    
    to
    <div class="portlet"
         id="portlet-folder-contents"
         tal:define="name user/getUserName"
         tal:condition="python:test(name=='Anonymous User',False,True)">
    
  11. Note that if access to the folder itself is restricted, executing the portlet in the fashion described above will cause Zope to redirect unauthenticated web site accesses to the login page prior to the execution of the Anonymous User test. Because the login page also renders the boxes listed in left_slots and right_slots, Zope will redirect the user to a HTTP basic authentication prompt in order to avoid an infinite loop. This means that any unauthenticated portal access will prompt for HTTP basic authentication.

    To avoid this situation, make a copy of the portlet and change all references to the TAL keyword here to the explicit path of the folder object. For example, the header element

    <h5 tal:content="here/title_or_id">Folder Name</h5>
    
    becomes
    <h5 tal:content="root/portal-id/path/title_or_id">Folder Name</h5>
    
    (where portal-id/path is the URI of the folder from the Zope root, not from the portal root). Add this customized portlet to the portal's left_slots or right_slots property using the standard syntax here/copy_of_portlet_folder_contents/macros/portlet (where copy_of_portlet_folder_contents is the ID of the customized portlet).

    Yes. If you are new to Zope, page templates, and the Zope security model, this is very confusing.

« November 2008 »
Su Mo Tu We Th Fr Sa
1
2345678
9101112131415
16171819202122
23242526272829
30
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: