[ZPT] ZPT and Paths

Evan Simpson evan@zope.com
Thu, 11 Oct 2001 16:42:24 -0400


Amy Schmidt wrote:

> I'd like to call an image using it's Zope id in a Page
> Template without hardcoding the path


Without hardcoding *any* of the path?  How would you specify which image 
you meant?  You could do this with a catalog query, I suppose.  Or do 
you keep all of your images in the same location, and you just don't 
want to have to repeat that location in each image reference?


> to find any documentation on that. Note that the Page
> Template and image reside in different directories in
> Zope. If there's no way to reference the image without
> hardcoding the path, I can't see any reason why using
> TAL in ZPT is better than straight HTML for image
> references. See example below. Am I missing
> something???
> 
> HTML only
> <img src="../images/subdir/myimage.gif">
> 
> HTML/TAL
> <img tal:replace="here/images/subdir/myimage.gif">

Well, one minor advantage to the TAL version is that it automatically 
adds width, height, and any other tags that you defined on the image.

If you just want to abstract out the image folder's location, you could 
make the path a property in your site root, and do something like:

<tal:block define="global images python:path(here.image_folder_path)"/>
<html>
...
   <img tal:replace="images/myimage.gif">
   <img tal:replace="images/myotherimage.png">
...
</html>

Cheers,

Evan @ Zope