Gossamer Forum
Home : Products : Gossamer Links : Discussions :

sub routine needs a variable

Quote Reply
sub routine needs a variable
Just a quick question - in the help file, there is a subroutine for displaying the list of the top five links - how does it know what arguments to take? If the subroutine is called 'top_five' then how would I call it in a template file?

Thanks,
Laura.

Quote Reply
Re: sub routine needs a variable In reply to
Follow the instructions and add it as a global.


In the admin area under globals you will see two blank fields - a text field and textarea. In the text field you add top_five then add the code into the textarea enclosed by:

sub {

CODE

}

.....then put <%top_five%> in your templates.

Paul Wilson.
new - http://www.wiredon.net
Quote Reply
Re: sub routine needs a variable In reply to
I've done all that. If the first line of the sub routine is

$temp = shift;

how do I put the variable into the routine. This may be a silly question but its the syntax of the template parser that I'm not used to. In perl I would just write

&top_five('Variable');

So how do I write this in a template?

Thanks,
Laura.

Quote Reply
Re: sub routine needs a variable In reply to
You don't need to change anything - just cut and paste the code from the readme into a global and then add the tag into the template.

Paul Wilson.
new - http://www.wiredon.net
Quote Reply
Re: sub routine needs a variable In reply to
Sorry, I was using the subroutine in the help file as an example. I have written a subroutine to display the rating for a link graphically and it needs to know what the rating for an individual link is to be able to display it. If I call <%rating_sub%> from the link template then I need to tell it what the rating of the link is somehow.

Sorry for not explaining it fully to begin with - just thought it would have a simple answer.

Quote Reply
Re: sub routine needs a variable In reply to
Here is a simple answer:

Why not use the existing image for rating mod?

Paul Wilson.
new - http://www.wiredon.net
Quote Reply
Re: sub routine needs a variable In reply to
Hi,

The first argument is a list of all the tags on the page. So you can do:

my $tags = shift;
my $ratings = $tags->{Rating};

to get the rating. You can access/change/set any of the tags by modifying that hash.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: sub routine needs a variable In reply to
Alex,

Thanks a lot. I ended up using a template file to solve that particular problem but I think this is quite an important piece of information to have learnt for the future.

Laura.