throwing exceptions when <img src=...> does not exist
hi, i have a little problem re: img and dtml-try tags: there are images stored on an external server - these are named after student's universtity usernames e.g. lreilly.gif. represents moi, lee reilly. the problem is that it is not guaranteed that such an image is stored for *every* student so i want to do something like... <dtml-try> <img src="d:\<dtml-var uname>.gif" width="240" height="180"> <dtml-except> <img src="d:\dilbert.gif" width="240" height="180"> </dtml-try> i.e. if the student gif exists display it otherwise display the file dilbert.gif. if the files were stored on zope then modifying the <img> tags to plain <dtml-var uname> would work fine except that (i) they're not stored on my server (ii) <dtml-var uname> would display the username and not the image (id=username) - i think this can be overcome though. is there anyway to adapt the above code to actually *throw* an exception when the image is not located. the results of the above code are as follows: if the files exist => it is displayed if the file doesn't exist => nothing is displayed anybody have any thoughts / advice? cheers, lee -- Lee Reilly mailto:lee.reilly@ntlworld.com http://www.footkick.co.uk
On Mon, 19 Feb 2001 23:29:17 +0000 Lee <lee.reilly@ntlworld.com> wrote:
hi,
i have a little problem re: img and dtml-try tags:
there are images stored on an external server - these are named after student's universtity usernames e.g. lreilly.gif. represents moi, lee reilly. the problem is that it is not guaranteed that such an image is stored for *every* student so i want to do something like...
<dtml-try> <img src="d:\<dtml-var uname>.gif" width="240" height="180"> <dtml-except> <img src="d:\dilbert.gif" width="240" height="180"> </dtml-try>
i.e. if the student gif exists display it otherwise display the file dilbert.gif.
This code will only throw an exception if the attribute 'uname' doesn't exist, which is not what you're looking for. The whole 'd:/' business looks like it might be a source of trouble too, but maybe that's just the way your setup works.
if the files were stored on zope then modifying the <img> tags to plain <dtml-var uname> would work fine except that
(i) they're not stored on my server
You have a complicated problem then :-)
(ii) <dtml-var uname> would display the username and not the image (id=username) - i think this can be overcome though.
is there anyway to adapt the above code to actually *throw* an exception when the image is not located. the results of the above code are as follows:
if the files exist => it is displayed if the file doesn't exist => nothing is displayed
I'd try one of three things: - Move the images onto your Zope server as either images stored in the ZODB, or use the ExtImage product to store the image data on the filesystem and the metadata inside Zope. This is probably a nuisance, or you would have done it already. - Store information per user to indicate whether they have an image on that server or not. Which involves determining that information in the first place and keeping it up to date, which is not fun. - Write an external method that goes out and checks whether the image in question actually exists on the server. You might need to do an HTTP HEAD on the expected image URL, but this is roughly what the user's browser will have to do, so it's pretty much the canonical test. John
participants (2)
-
John Morton -
Lee