Tuesday, August 2, 2011

Displaying (and filtering) the contents of a folderish content type

If you need to list the contents of a folderish content type you can include something like this in your page template:

<fieldset id="folder-listing">
    <legend i18n:translate="">Contents</legend>
    <tal:block define="listing_macro context/folder_listing/macros/listing">
        <metal:use_macro use-macro="listing_macro" />
    </tal:block>
</fieldset>

Note that listing is a huge macro inside the skins/plone_content/folder_listing.pt template in the CMFPlone product.

You can even do things like content filtering or limiting the number of items shown with this macro:

<fieldset id="folder-listing">
    <legend i18n:translate="">Contents</legend>
    <tal:block define="listing_macro context/folder_listing/macros/listing;
                       contentFilter python:{'portal_type': ['File']};
                       limit_display python:5">
        <metal:use_macro use-macro="listing_macro" />
    </tal:block>
</fieldset>

Enjoy!

(Tested under Plone 4.1)