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

Template Global Tutorials

Quote Reply
Template Global Tutorials
Hi there...

I only recently started out with PERL/CGI and I love it. Easy to understand and to use. Even so, there are still a few things I am having trouble with. One of them is template globals, specifically database connections to mySQL, read and write of information to the database, and also, I would like to know what all the global variables are, functions of modules etc. If anyone could please point me in the right direction, I would be grateful.


Sacrifice is not about what you lose,
it is about what you gain in the process.
Quote Reply
Re: [EZFrag] Template Global Tutorials In reply to
Hi,

Your best bet, is to take a look at the tutorials in the admin panel (click "Help" on the top right of the frame - then goto "GT Module Documentation"). Have a look at the GT::SQL section:

http://www.yoursite.com/cgi-bin/admin/admin.cgi?do=help&topic=/GT/SQL.html

Heres a few basic pointers:

<%test_sub("Test")%> -
Code:
sub {

my $val = $_[0];

}


$val would contain the value "Test"

A simple DB connection:

<%get_total_links%>
Code:
sub {

return $DB->table('Links')->count({ isValidated => 'Yes' });

}


Getting a list of categories:
Code:
sub {

my $tbl = $DB->table('Category');
$tbl->select_options('ORDER BY Full_Name');

my $sth = $tbl->select( { FatherID => 0 } ) || die $GT:}:SQL::error; # get root categories only - FatherID 0

my $back;
while (my $hit = $sth->fetchrow_hashref) {
$back .= qq|$hit->{Full_Name}<br />|;
}

return $back;
}

This is really only scratching the surface of what you can do though :)

Hopefully that's enough to get your started =)

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] Template Global Tutorials In reply to
Yes, Thanks alot.
Just hope I can find something about writing to a database Smile


Sacrifice is not about what you lose,
it is about what you gain in the process.
Quote Reply
Re: [Andy] Template Global Tutorials In reply to
Great, thanks for the link. It helped a lotSmile


Sacrifice is not about what you lose,
it is about what you gain in the process.
Quote Reply
Re: [EZFrag] Template Global Tutorials In reply to
Hi,

Putting into a table is pretty easy :)

Code:
sub {
my $add;
$add->{Field_Name} = "bla";

$DB->table('Table_Name')->add($add) || die $GT::SQL::error;
}

..or:

Code:
sub {
$DB->table('Table_Name')->add( { Field_Name_1 => "value", Other_Field => "something" } ) || die $GT::SQL::error;
}

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] Template Global Tutorials In reply to
Everything seems so easy now.....


Sacrifice is not about what you lose,
it is about what you gain in the process.
Quote Reply
Re: [EZFrag] Template Global Tutorials In reply to
haha. it does get more complex - but thats the core of what you need to really know :) Its always good to look at how other globals are done too - may seem scary with some of the more complex ones - but its a good learning base :)

Heres a load of "globals" I've converted into on plugin:

http://www.ultranerds.com/...s/ULTRAGlobals_L217/

Install it, then view the /admin/Plugins/ULTRAGlobals.pm file - and you should see all th globals, and how they work :) (should give you a good idea on how to pass back tags, loops etc)

Enjoy Cool

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] Template Global Tutorials In reply to
Nice. I'll give them a try after I finished this minor Globals of mine.
Thanks Andy.


Sacrifice is not about what you lose,
it is about what you gain in the process.
Quote Reply
Re: [Andy] Template Global Tutorials In reply to
Quote:
sub {
my $add;
$add->{Field_Name} = "bla";
$DB->table('Table_Name')->add($add) || die $GT::SQL::error;
}

....or more syntactically correct....

Code:
my $add = {};
Quote Reply
Re: [Wychwood] Template Global Tutorials In reply to
True, not sure it matted so much in global though Smile Only real time I guess it could become confusing is if you have a hashref, and variable with the same name :)

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] Template Global Tutorials In reply to
A hashref IS a variable Crazy

Quote:
Only real time I guess it could become confusing is if you have a hashref, and variable with the same name :)

That's not even possible. If you code with warning on (which you should do by the sounds of it) then you would see why you need the = {}; part.
Quote Reply
Re: [Wychwood] Template Global Tutorials In reply to
You don't *need* the = {} part:

perl -wle 'use strict; my $foo; $foo->{bar} = "baz"'

Adrian