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

Plugin > template problems with 2.2 upgrade.

Quote Reply
Plugin > template problems with 2.2 upgrade.
Hi,

I use the following plugin to customize the display of a link depending on what category it is in. Since upgrading to 2.2, I am having trouble reading the passed variables at the template. This plug in worked fine before the upgrade. Weird.

Code:

# ==================================================================
# Plugins::Link_Display - Auto Generated Program Module
#
# Plugins::Display_Link
# Author : MP
# Version : 1
# Updated : Fri Apr 9 12:57:47 2004
#
# ==================================================================
#
package Plugins::Display_Link;
# ==================================================================
use strict;
use GT::Base;
use GT::Plugins qw/STOP CONTINUE/;
use Links qw/$CFG $IN $DB/;
use GT::Dumper;
# Inherit from base class for debug and error methods
@Plugins::Display_Link::ISA = qw(GT::Base);
# Your code begins here! Good Luck!

# PLUGIN HOOKS
# ===================================================================

sub site_html_link {
# -------------------------------------------------------------------
# This subroutine will get called whenever the hook 'site_html_link'
# is run. You should call GT::Plugins->action ( STOP ) if you don't
# want the regular code to run, otherwise the code will continue as
# normal.
#
my (@args) = @_;
# Do something useful here
my $cat_db = $DB->table ('Category')|| die $GT::SQL::error;
my $catlink_db = $DB->table('CatLinks')|| die $GT::SQL::error;
my $p = (ref $_[0] eq 'HASH') ? shift : {@_};
my $linkID = $p->{'ID'};

# get the catID for the current link
my $catID = $catlink_db->select ( { LinkID => $linkID } , ['CategoryID'] )->fetchrow;
my $linkType = $cat_db->select ( { ID => $catID } , ['Template'] )->fetchrow;

# add link new vars to @args
$args[0]{linkType} = $linkType;





# put carriage returns into the description
# $args[0]{'Description'} =~ s/\r?\n/<br>/g;



print Dumper(\@args);
return @args;
}
# Always end with a 1.
1;


The weird thing is that I can see the linkType variable in the args dump at the top of the page, but it doesn't make it through to the template itself.

I'm stumped. Anybody have any ideas?

Thanks,
Mike
Quote Reply
Re: [Swaylock] Plugin > template problems with 2.2 upgrade. In reply to
2.2.0 changed so that by default the site_html_link hook isn't called - instead, the code goes through Links::SiteHTML::tags('link'), which is mapped to the plugin hook site_tags_link, which returns the variables allowing you to do: <%include link.html%>, which is much more effecient. What'd I recommend doing is throwing a post hook onto site_tags_link, then adjusting the hash reference returned as required (see site_tags_link in Links/SiteHTML.pm). A plugin on site_tags_link will also affect the old site_html_link, as site_html_link uses site_tags_link internally.

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com