Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

How to show a pic for cat

Quote Reply
How to show a pic for cat
Hi all, to improve the handling of the site, i try to have a field for uploading a pic for every cat.
The problem now is to show it.

For links i use this:

Code:
sub {
my ($rec) = @_;
my $id = $rec->{ID};

if ($rec->{File1}) {
my $links_db = $DB->table('Links');
my $fh = $links_db->file_info( 'File1', $id );
my $location = $fh->File_RelativePath;
if ($fh->File_Name =~ /\.(jpg|gif)$/) {
return qq~ <img src="/imgup$location"> ~;
}
else {
return "Invalid file name.";
}
}
else {return "";}
}


So i have to change the db and the name of the column.
But what´s with

my ($rec) = @_;
my $id = $rec->{ID};


is it $rec ?
then $rec->{what} ?

Robert
Quote Reply
Re: [Robert] How to show a pic for cat In reply to
Could you explain a little more what you mean...Im not sure I understand.
Quote Reply
Re: [Paul] How to show a pic for cat In reply to
To show a file for a link you do this:
1. A new field for table links
2. a global for this file
3. Code for the template.

Now i want do the same for the cat-table
and stuck with the global, while i dont know
which information is there to choose from.

(On Links you have $rec->{ID} ... )
Robert
Quote Reply
Re: [Robert] How to show a pic for cat In reply to
Hi Robert

I don't think you need a global for this.

Add an image column in your category table,then in subcategory call it via:

<%-- This is only useful if you have added an Image column to your category table --%>
<%if Image%>
<img src="<%build_root_url%>/images/<%Image%>">
<%else%>
<img src="<%build_root_url%>/images/standard_image.gif">
<%endif%>

Regards

minesite
Quote Reply
Re: [minesite] How to show a pic for cat In reply to
Yes, i need a global for that.
The problem is solved:
Code:
sub {
my $tags = shift;
my $pic = $tags->{ID};
if ($tags->{CatPic}) {
my $cat_db = $DB->table('Category');
my $fh = $cat_db->file_info( 'CatPic', $pic );
my $location = $fh->File_RelativePath;
if ($fh->File_Name =~ /\.(jpg|gif)$/) {
return qq~<img src="/imgCat$location"> ~;
}
else {
return "Invalid file name.";
}
}
else {return "";}
}

Robert