Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listing contents of subfolders in a Plone folder view

Tags:

plone

On a Plone site with the structure

root
   +-topic1
   |    +-page1
   |    +-page2
   |
   +-topic2
        +-page3
        +-page4

I want to have a view for folder root that lists the contents of the subfolders, like:

[http://host/plone/root/]

TOPIC1

- page1
- page2

TOPIC2

- page3
- page4

with "TOPIC1" and "TOPIC2" as headings and "page1" etc. linking to the actual pages.

Simply using a collection aggregating the pages in the topic1 and topic2 folders is not enough since it doesn't generate the subheadings.

I have searched the Plone products repository as well as the web for an extension providing a view like this, with no success. There are sources saying this can be done with custom Display Views, but since I am new to Plone, I hesitate to dig into hacking these.

Is there a Plone product/extension that can provide such a view on subfolder contents?
Or is there even a built-in solution that I am not aware of?

like image 799
fbmd Avatar asked Apr 02 '11 22:04

fbmd


1 Answers

I figured it out.

Basically, what you want to do is extend the folder_summary_view template to include a content list for folder and collection items.

  1. Create a copy. In the ZMI, go to portal_skins/plone_content/folder_summary_view and hit Customize. Go to the copy at portal_skins/custom/folder_summary_view and rename it to (for example) list_contents.

  2. Activate it as folder view. Go to portal_types/Folder and manually add list_contents to the list in Available view methods.

  3. Make sure the view only shows folders and collections. Wrap the code that generates the entry details in <tal:general_check condition="python: item_type in ('Folder', 'Topic')"> GENERATE ENTRY </tal:general_check>

  4. Add the code for listing the item contents. You can steal it from portal_skins/plone_content/folder_listing since this already does what is needed. Copy the <metal:listingmacro> ... <metal:listingmacro> part, but replace the folderContents definition in <tal:foldercontents> with this line to retrieve the contents:

folderContents folderContents|nothing;
folderContents python:item_object.queryCatalog(**contentFilter) or
item_object.getFolderContents(contentFilter, batch=True, b_size=limit_display or 100);

(all in one line)

Note: item_object is the name given to the item in the outer listing.

If you activate list_contents as a folder view now, it works exactly as demanded in the question.

Warning: This is a copy-paste-hack by a Plone novice that works for me™. Use at your own risk.

like image 122
fbmd Avatar answered Nov 15 '22 11:11

fbmd