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

Template global that pulls data from another table

Quote Reply
Template global that pulls data from another table
Maybe someone can help me with this... I have been beating my head against the wall for about 45 minutes and can't find the answer to this on the forum or in the help. I know you can do it, I just don't know how.

I am trying to add a function to the "Template Globals" that will be referenced from the detailed page with:
<%venue_title%>

I need the sub to return the "title" field from another table named "Venues". My problem is that I can't seem to reference any of the data in the Links table (specifically a field named "venueid" that I added ... or even ID for that matter) from within my sub. What am I missing? Here is what I have:
<PRE>
sub {
my %rec = @_;
my $ven_db = $DB->table('Venues');
my $sth = $obj->select({ ID => $rec{'VenueID'} });

if(my $row = $sth->fetchrow_hashref) {
return $row{'Title'};
}

return "Invalid Venue!";
}
</PRE>
From what I see in the docs, @_ (sub params) is set to a hashset of all the fields of the record that was opened for the current page. Is this not the case?

Thanks!
-Shaun

Quote Reply
Re: Template global that pulls data from another table In reply to
Did you create a DEF file for this new table?

Regards,

Eliot Lee
Quote Reply
Re: Template global that pulls data from another table In reply to
I thought I replied to this... there is a thread here by Alex, I don't have the number, but search in the Links SQL Discussion area for "Template globals" on how to do this.

Part of the problem, I think, is that you are trying to pass a hash, not a hash_ref to the subroutine. I think all the routines look for hash_refs.

And, as Eliot said, any table that you try to access through the standard Table-> methods, _must_ have a .def file to work properly.




PUGDOGŪ Enterprises, Inc.
FAQ:http://LinkSQL.com/FAQ
Forum:http://LinkSQL.com/forum
Quote Reply
Re: Template global that pulls data from another table In reply to
Pugdog,
I got your reply today... sorry for the double post.

Thanks for all the help guys... I did have the def file for my new table, all I was missing was:
"my $tags = shift;" (I was using "my %tags = @_;")

Thanks!
-Shaun