Hi,
First off, just a little context here. This function will be saved in the Template Globals as:
tag_name => sub { .. }
in the admin. Now when you use <%tag_name%> in any template, it will run the given function.
my $tags = shift;
The first argument to the function will be the list of other tags on the template. So if you had <%tag_name%> in the link.html template, in $tags would be a hash of all the fields available in link.html.
my $link_id = $tags->{ID} or return;
This assumes that on the template you are using, you have the ID number of the link you want. This may be wrong, as I'm not sure exactly what you are doing. If there is no ID tag on this page, then we return as there is not much we can do.
my $catlnk_db = $DB->table('CatLinks');
This gives you a GT::SQL::Table object that works off of the CatLinks table.
my $sth = $catlnk_db->select ( { LinkID => $link_id } );
This selects out of the database the row where LinkID = the ID on this template.
my $results = $sth->fetchrow_hashref;
This returns the results as a hash. So it would look like { LinkID => 5, CategoryID => 3, CustomColumn => ... }.
You can now either return what you want printed, or if you just return the hash, then you will have <%LinkID%>, <%CategoryID%> and <%CustomColumn%> tags available on the page.
Let me know if this makes sense,
Cheers,
Alex
--
Gossamer Threads Inc.
First off, just a little context here. This function will be saved in the Template Globals as:
tag_name => sub { .. }
in the admin. Now when you use <%tag_name%> in any template, it will run the given function.
my $tags = shift;
The first argument to the function will be the list of other tags on the template. So if you had <%tag_name%> in the link.html template, in $tags would be a hash of all the fields available in link.html.
my $link_id = $tags->{ID} or return;
This assumes that on the template you are using, you have the ID number of the link you want. This may be wrong, as I'm not sure exactly what you are doing. If there is no ID tag on this page, then we return as there is not much we can do.
my $catlnk_db = $DB->table('CatLinks');
This gives you a GT::SQL::Table object that works off of the CatLinks table.
my $sth = $catlnk_db->select ( { LinkID => $link_id } );
This selects out of the database the row where LinkID = the ID on this template.
my $results = $sth->fetchrow_hashref;
This returns the results as a hash. So it would look like { LinkID => 5, CategoryID => 3, CustomColumn => ... }.
You can now either return what you want printed, or if you just return the hash, then you will have <%LinkID%>, <%CategoryID%> and <%CustomColumn%> tags available on the page.
Let me know if this makes sense,
Cheers,
Alex
--
Gossamer Threads Inc.