plonetemplate-talzpt

Plone 4 Zope Display Contents of specific folder TALES


Problem

I have a customer that wishes to display the entire contents of a certain folder (containing images) on their search page, should the search return 0 results. The folder is located at mysite.com/images

Setup:

As a test environment I have setup a seperate site with the following structure:

ROOT
|-Folder1 <-- current directory I am viewing
| |-images
|-Other folders

I modified the folder_summar_view template, to include the following code (I decided to modify a view to see if I could hack that to pieces to make it do what I want):

<div tal:define="image context/images/getFolderContents">
  <div tal:content="i" tal:repeat="i image" />
</div>

What I see:

<Products.ZCatalog.Catalog.mybrains object at 0x9d2ddb8>

Things I've tried and further explanations

I was under the assumption that when the context/images/getFolderContents returns a brain for the 'objects' in my images folder, I could then iterate through each 'object' using my tal:repeat statement below it. Then display them on my page.

If I just use the following code:

<div tal:content="context/images/getFolderContents" />

My output is very similar to the above 'What I see' section:

<Products.ZCatalog.Catalog.mybrains object at [...]>

where [...] is another number

I've been doing some research and reading the Plone Theming book, but my code is similar to their tal:repeat examples on page 169, it seems the only difference is they are not using this on a brain (as far as I can tell).

I tried this, although it produced the same results (not sure why I tought it wouldn't):

<div tal:define="image python:context.images.getFolderContents()">
  <div tal:content="i" tal:repeat="i image" />
</div>

I don't seem to be able to 'get inside' the returned brain. Everything I've looked for online doesn't quite help that much, I've also trawled through the atct_album_view and folder_listings templates to know avail. - I think I'm overlooking or missing something.

The first link I stumbled across was this, however I have moved on since that as although similar, it's not quite what I was trying to do.

The Plone guys on their chat room were kind enough to give me the context/images/getFolderContents statement, I tried to press on without asking for help again but it seems I've hit a wall.

More stuff I've tried

Using this link as inspiration I decided to try the following:

<div tal:define="image context/images/getFolderContents">
  <div tal:content="image/getURL" />
</div>

But that throws an error when I try to view the template. The error reads along the lines of the 'getFolderContents brain does not have the attribute getURL' - Although image/Title displays the name of the folder, but that's not really what I need.

I also found this link however because I am making use of the default search, I don't really want to have to edit python scripts as I fear it may adversely effect the normal Plone site search. Also in this link they seem to be making use of more Python scripts. - To expand on this point, I'm not sure on how these scripts 'link' with page templates (how they know to 'talk' to one another).

Conclusion

In conclusion I need to display all of the images contained within a folder named "images" located at the root of my site, I am unable to access the contents of a returned brain using getFolderContents. And other than displaying the title of the "images" folder or the brain identifcation (<Products.ZCatalog.Catalog.mybrains object at 0x9d2ddb8>) , I have had no luck. Any help or ideas welcomed!


Solution

  • As getFoldercontents returns a list of brains i cant see how your code can work. Just repeat over it with something like that :

    <tal:block tal:repeat="image context/images/getFolderContents">
      <a tal:attributes="href image/getURL" tal:content="image/Title"/>
    </tal:block>