[Zope] - img src question

Amos Latteier amos@aracnet.com
Mon, 25 Jan 1999 17:22:21 -0800


At 04:44 PM 1/25/99 -0800, Michael Bernstein wrote:
>When I call an image from the index_html method in the root by using
><img src="Images/myimage.gif">, the image is retrieved as
>http://localhost:9673/Images/myimage.gif
>
>But when I go to a subdirectory that does not have it's own index_html,
>it inherits the index_html method from it's parent, but retrieves the
>image as http://localhost:9673/Subdir/Images/myimage.gif, forcing the
>browser to re-download the image.
>
>How do I get Zope to evaluate the images URL as relative to the root,
>instead of chaining the Folder off of the current Directory (BTW I just
>realized that it works this way because folders are methods too, and
>thus subject to acquisition, very cool)

I think that you are thinking too hard. If you want to reference an object
with an absolute URL, use an absolute URL, for example <img
src="/Images/myimage.gif">

Unfortunately, depending on your web server configuration, this absolute
URL won't work. For example if your Zope root Folder is:

http://example.com:9673/Zope/

Then using the <img src="/Images/mygif.gif"> wouldn't work, since it should
be <img src="/Zope/Images/mygif.gif"> You could just use the longer
absolute URL, but what if you change your server configuration? Then you'll
need to update the URL. Yuck.

Luckily, you can generate an absolute URL with some help from built-in
REQUEST variables. For example, 'BASE1' is a useful URL which gives you the
server name, port, and the scriptname. So to get a correct absolute URL, no
matter what your web server configuration use this:

<img src="<!--#var BASE1-->/Images/mygif.gif">

Now, things get trickier if you acquire an object and then want to find out
what its canonical or absolute URL is. But that's another story, and
hopefully one that will be cleared up in the next release.

-Amos

P.S. It's true that Folders, like most Zope objects can acquire and be
acquired. But that doesn't mean they're methods ;-)

P.P.S. Read more about special REQUEST variables in the DTML User's Guide:

http://www.zope.org/Documentation/Guides/DTML/