Oliver Frommel wrote:
Hello,
although I already created some sites with Zope I now encountered a problem that I am not able to solve with acquisition, i.e. to make a parent subfolder work as a fallback resource. Directories look like this:
/pics/logo.gif /dir/subdir1/pics/logo.gif /dir/subdir1/index_html (subdir1 is a zclass and index_html a method of it) /dir/subdir2/pics/logo.gif /dir/subdir2/index_html (subdir2 is a zclass and index_html a method of it) /dir/subdir3/pics/ (empty!) /dir/subdir3/index_html (subdir3 is a zclass and index_html a method of it)
The index_html contains a reference to the pic: <img src="pics/logo.gif"> Now when the subdirX/pics/ doesn't not contain a logo.gif, acquisition also does not work because it stops on finding the pics folder in the subdirX. This is exactly the scenario, Rik Hoekstra describes in http://www.zope.org/Members/Hoekstra/ChangingZopeContexts.
Unfortunately non of the workarounds he mentions are appropriate because a) I need an image folder for each subdir (see below) b) I can't reference images from the parent c) the pic directories need to have the same name
this all because the rationale behind this is to enable index_html to look differently _dependent_ on the existence of logo.gif. the site designers are meant to be able to change index_html's appearance just by uploading a new logo.gif. If this is not present, the one of the parent should be used.
I think it would work if I put the images directly in subdirX and in the root dir but this is pretty ugly and should only serve as a last ressort IMHO.
is there any way / product / trick to make this concept work with subdirs??
an explicit PythonScript (or DTML Method) should do the trick: include a PythonScript in your zclass (or somewhere else) with the following code (name: findlogo; standard bindings): try: getattr(context.pics, 'logo') # if logo is the name of the picture logo = context.pics.logo except AttributeError: logo = context.<fallbackdirectory>.pics.logo # in which fallback directory is your rootdir return logo instead of the <img srcs="pics.logo.gif"), make your index_html refer to <dtml-var findlogo> this should do the trick. I tested it on a very simple setup, where it worked. Let me know if this helps. hth Rik