Applying a custom view to a specific folder

by Dan Jacka last modified Sep 05, 2011 10:41 AM
How to create a one-off view for a particular folder in your site.

You have a custom content type. You want a folder full of objects of your type to be listed in some custom way. How do you do it?

Take a look at the Members folder in a freshly created Plone site. That's a regular folder with a custom view that lets a user search the folder's contents. To achieve this effect, inside the folder is a Python Script index_html containing:

member_search=context.restrictedTraverse('member_search_form')
return member_search()

This works because when a user browses to a folder, if Zope finds an object with the special name index_html inside that folder it will select that object rather than the folder itself. In this case the index_html looks up a member_search_form page template.

Create your own one-off views as Zope 3-style browser views; register them for the Products.ATContentTypes.interface.IATFolder interface.

Products.CMFPlone's Members folder setup illustrates how to use a GenericSetup import handler to create a index_html Python Script.