[Zope] conceptual problem with acquisition
Oliver Frommel
Oliver Frommel <oliver@aec.at>
Mon, 5 Mar 2001 15:02:44 +0100 (CET)
> 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
>
>
yes, thank you very much!
However I changed the PythonScript a bit to
a) take a variable
b) operate on strings, i.e. also return a string
PythonScript findimage, parameter "image":
try:
getattr(context.pic, image)
image = "pics/" + image
except AttributeError:
image = "dir/pics/" + image
return image
I call it from a DTML method like that:
<img src="<dtml-var "findimage('logo.gif')">">
yes, this is not nice, and I am not really content with it ..
how could I e.g. make your example work when using an image with a "normal"
name, i.e. period and extension. I think I can hardly make all Zope end users
(Designers, Editors ..) make switching from that to underscore naming!
> getattr(context.pics, 'logo') # if logo is the name of the picture
> logo = context.pics.logo
thanks for your help
--Oliver