Search code examples
ploneacquisition

Good ways to acquire resources from parent folders in Plone?


I have a Plone (4.0.1) site which requires changes in layout depending on the folder. Imagine a structure like:

University > Faculty A > Institute A1 > Person A11
                                      > Person A12
                       > Institute A2 > Person A21
...

Now if I put all needed resources (custom css file, images, etc.) into the ZODB, pages for person A11 would automatically pick up a fac-image.gif located in the Faculty A folder.

However, to avoid confusion, I do not want to expose fac-image.gif to the users. (This is all part of the framework which they're not supposed to touch anyway.)

If I register a resource, I can access stuff with ++resource++theme.images/path, but no acquisition from parents is taking place, so ++resource++theme.images/facultyA/instituteA1/fac-image.gif won't find the image. Even worse, I have a separate directory structure to maintain now.

What I'm currently doing is hand-rolling a "best effort" traversal process through a file system directory view that will try to go down the path, just stay where it is if the subdirectory doesn't exist (i.e. the resource tree doesn't have a subdirectory for person A11; instead of yelling 404 I stay at institute A1), and then try to acquire back up. Some trickery is involved for portal_factory and views, and I'm pretty sure I've missed more.

So: that surely isn't the way one is supposed to do it, but what is?


Solution

  • You can inspirate you from collective.phantasy that implements this use case for plone3 (change l&f for a folder container).