[Zope] referencing images in products

Dennis Allison allison@sumeru.stanford.EDU
Fri, 14 Feb 2003 14:54:13 -0800 (PST)


Thanks.  I actually solved the problem another way.  Basically 
images need to be registered.  So, in the product's __init__
method, I added:

        context.registerClass(
            Navigator.Navigator,
            constructors = Navigator.constructors,
            icon='www/nav.gif'
        )

        registerIcon('redarrow.gif')
        registerIcon('spacer14x12.gif')

where the registerIcon() method is local and defined 

def registerIcon(filename, idreplacer={}):
    # A helper function that takes an image filename (assumed
    # to live in a 'www' subdirectory of this package). It 
    # creates an ImageFile instance and adds it as an attribute
    # of misc_.MyPackage of the zope application object (note
    # that misc_.MyPackage has already been created by the product
    # initialization machinery by the time registerIcon is called).
    objectid = filename
    for k,v in idreplacer.items():
        objectid = objectid.replace(k,v)
    setattr(OFS.misc_.misc_.Navigator,
            objectid,
            App.ImageFile.ImageFile('www/%s' % filename, globals())
            )

I found similar code in a number of products.  This particular code came 
from the IssueTrackerProduct.

The image, when all this is said and done, are referenced from the
Product's dtml as, for example, 

     <img src="misc_/Navigator/redarrow.gif" alt="=>"> 


On Fri, 14 Feb 2003, Ulla Theiss wrote:
> 
> I have solved this task in the following way:
> 
> 1. The image is in 
> ${PRODUCT_PATH}/images/first.gif
>
> 2. In the product-code:
> 
> class myProduct(....):
>     first_icon = ImageFile('images' + sep + 'first.gif', globals())
> 
> 3. In the DTML-Code
> 	<img src="first_icon" border="0" alt="First Page">
> 
> Of course, this works only for static images. For dynamically created
> ones, I have a problem, too.
> 
> 
> I hope this may help you a little bit,
> 
> Dennis Allison schrieb:
> > 
> > I have a product which needs to reference some icons which are part of the
> > product.  Following the usual structure, the icons are www sub-directory of
> > the product.  The dtml that wants to reference the image is in the dtml
> > sub-directory.  What's the reference mechanism?
> > 
> >         <img src="../www/image.png">
> > 
> > in the dtml code does not resolve to the image.  Nor doe the equivalent <dtml-var ...>
> > formulation.  What should the reference be?
> >