Gossamer Forum
Quote Reply
Help global
hi,

I want to make a global that return category url as numbers.
Like, build_root_url/2/20/200/index.html

The following is the global that I made, but it just print out the sub as is.

Code:

global cat_static,

sub{
my $tags=shift;
my $id=$tags->{ID};
my $cat_db=$DB->table('Category');
my $sth=$cat_db->select(['FullName'],{ID=>$id});
my $fullname=$sth->fechrow_array;

my $output;
my @list=split(/\//,$fullname);
foreach my $list(shift@list){
my $sth2=$cat_db->select(['ID'],{'Name','=','$list'});
my $number=$sth2->fechrow_array;
$output.="\/$number";
}
return $output;
}

then in Category Template I would loke to put <a href="<%build_root_url%><%cat_static%>/index.html">here</a>.

Can anyone tell me how to do that or correct the sub ?
### Moto ###
Quote Reply
Re: [Moto] Help global In reply to
This is a built in feature of GLinks, you change it in setup
build_category_format
Quote Reply
Re: [Alba] Help global In reply to
Hi thanks for the reply,

Which version are you referring to ?

I am using LinksSQL v2.1.2.and set foreign char Yes.
I suppose there is not build_category_format in my version.

I want my users go to dynamic pages form static, and go back to static from dynamic.

When dynamic, urls are something like "page.cgi?g=2/20/200/index.html&d=1". Right?

I also want to have static urls that take users back to static pages form dynamic, which are not overwritten by LinksSQL.

That's the reason I want to make this global.

And thanks for reading my rusty English!

### Moto ###
Quote Reply
Re: [Moto] Help global In reply to
Hi,

I'm not quite sure you're doing it right Unsure

Any global, should start with sub {, and end in }

For example;

Code:
sub {
# do something
return@args;
}

So, your global should look more like;

<%cat_static%>

Code:
sub {

my $tags = shift;
my $id = $tags->{ID};
my $cat_db = $DB->table('Category');
my $fullname = $cat_db->select(['FullName'],{ID=>$id})->fetchrow;


my $output;
my @list=split(/\//,$fullname);
foreach my $list(shift@list){
my $number =$cat_db->select(['ID'],{'Name','=','$list'})->fetchrow;
$output.= qq{/$number};
}
return $output;
}

If using later version of GLinks ( > 3.0 ), then you may need to change the last line;

return $output;

..to;

return \$output;

I've also rewritten some parts for you, i.e;

my $number =$cat_db->select(['ID'],{'Name','=','$list'})->fetchrow;

..instead of 2 lines of code Smile

Hope that helps.

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!
Quote Reply
Re: [Andy] Help global In reply to
Hi Andy,

Thanks for your help, I got this global worked out! Smile
Final code is as follows;
Code:
sub {
my $tags = shift;
my $id = $tags->{ID};
my $cat_db = $DB->table('Category');
my $fullname = $cat_db->select(['Full_Name'],{ID=>$id})->fetchrow;
my $output;
my @list=split(/\//,$fullname);
foreach my $list ( @list) {
my $number = $cat_db->select(['ID'],{ Name => $list })->fetchrow;
$output.= qq~$number/~;
}
return $output;
}

Thanks again!
### Moto ###