Gossamer Forum
Home : Products : Gossamer Links : Discussions :

if image exists else use default

Quote Reply
if image exists else use default
Hi folks,
Been trying to get this working, i've added a column to the links as "photo", and added a global I found while searching for a solution, which is as follows:

Named Global is: file_url

sub {
my $tags = shift;
my $file = $DB->table('Links')->file_info ('photo', $tags->{ID});
my ($url) = $file =~ m,/full/root/url/images/stored/(.*),;
return $url;
}

In the links.html page, i added a if / else statement to figure out whether or not a photo exists, if it does use it, else use the other in the default which is:

<%if photo%>
Has a image
<img src='http://www.something.com/images/stored/<%file_url%>' alt='' class='photo' />
<%else%>
No image
<img src='http://www.something.com/images/stored/awaiting.jpg' alt='' class='photo' />
<%endif%>

The problem i'm having is the url is coming back blank as "images/stored" if there's no image there, and its not using the 'else' statement.

The database entry is:

photo / varchar 255 / null = yes / type file and is Hashed.

The result of this, is the photo works if it exists, the url doesnt complete if there isn't, i've also tried setting the default in the database, however this provides another problem, because if i use <%photo%><%file_url%> it works fine if there is no image submitted, but if there is one there, it obviously ouputs: storage/images/nameoffile.jpg as well as 1-nameoffile.jpg

Any ideas how i can over come this? i think i'm almost there.

Cheers
Quote Reply
Re: [ryanv2] if image exists else use default In reply to
You should probably just use:
Code:
<%if photo%><img src="<%config.db_cgi_url%>/jump.cgi?ID=<%ID%>;view=photo" /><%endif%>

Adrian

Last edited by:

brewt: May 26, 2006, 3:18 PM