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

Subroutine Globals - How to use a variable passed from a template?

Quote Reply
Subroutine Globals - How to use a variable passed from a template?
I have a custom global, <%myglobal%> in a template.

The global is a Perl subroutine.

I would like to call the global in several places within the template but only certain portions of the subroutine code to be executed depending on either a variable being passed in on the template or setting/unsetting a variable accessible in that template.

E.g. <%myglobal('region1')%> or <%myglobal('region2')%>

sub {

if 'region1'

do this

else if 'region2'

}

The idea is to reuse a subroutine that has some common code within the same template, the problem is I need to pass in an indicator from the template that can be used in that subroutine as a switch-on variable.

Any help would be appreciated.
Quote Reply
Re: [scorpioncapital] Subroutine Globals - How to use a variable passed from a template? In reply to
Try;

Code:
sub {

my $type = shift;

if ($type eq "region1") {

# do stuff here for region 1

} elsif ($type eq "region2") {

# do region stuff here....

} else {

# do some stuff here...

}

}


Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!