We had a custom map searching plugin written a while ago, and now we are trying to do some enhancements. The only problem is that we are unable to use globals in the templates this plugin uses. What must I do to get the globals working?
Jul 30, 2015, 8:07 AM
Veteran / Moderator (18441 posts)
Jul 30, 2015, 8:07 AM
Post #2 of 15
Views: 11277
Can you explain a bit more? You don't give us much to go on
What template? Part of the Glinks templates, or a different system alltogether?
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:
unable to use globals in the templates this plugin uses.What template? Part of the Glinks templates, or a different system alltogether?
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!
Jul 31, 2015, 1:41 AM
Novice (15 posts)
Jul 31, 2015, 1:41 AM
Post #3 of 15
Views: 11265
OK, I'm going to try and give some more details. I'm referring to the Glinks templating system when I talk about templates.
The finder plugin uses its own .cgi file (let's call it finder.cgi) instead of the page.cgi file generally used by the Glinks app. Here is the finder.cgi file:
use warnings;
use strict;
use CGI::Carp qw(fatalsToBrowser);
use lib '/server/path/to/cgi-bin/subsection/admin';
use lib '/server/path/to/cgi-bin/subsection/admin/lib';
use Geo::Helpers;
my $geo = Helpers->new ('full', '/server/path/to/cgi-bin/subsection/admin/finder.conf');
$geo->Run;
Here is the typical page.cgi code:
use strict;
use lib '/server/path/to/cgi-bin/subsection/admin';
use Links qw/$PLG/;
use Links::User::Page;
local $SIG{__DIE__} = \&Links::fatal;
Links::init('/server/path/to/cgi-bin/subsection/admin');
Links::init_user();
if ($PLG->dispatch('check_request', \&Links::check_request)) {
$PLG->dispatch('handle_page', \&Links::User::Page::handle);
}
The page that is displayed when I'm using the frontend of finder.cgi is in the template finder.html. If I try to insert any of the globals set in the backend of the Glinks installation, it claims that it is an 'unknown tag'.
Hopefully this provides some clarification.
The finder plugin uses its own .cgi file (let's call it finder.cgi) instead of the page.cgi file generally used by the Glinks app. Here is the finder.cgi file:
Code:
use warnings;
use strict;
use CGI::Carp qw(fatalsToBrowser);
use lib '/server/path/to/cgi-bin/subsection/admin';
use lib '/server/path/to/cgi-bin/subsection/admin/lib';
use Geo::Helpers;
my $geo = Helpers->new ('full', '/server/path/to/cgi-bin/subsection/admin/finder.conf');
$geo->Run;
Here is the typical page.cgi code:
Code:
use strict;
use lib '/server/path/to/cgi-bin/subsection/admin';
use Links qw/$PLG/;
use Links::User::Page;
local $SIG{__DIE__} = \&Links::fatal;
Links::init('/server/path/to/cgi-bin/subsection/admin');
Links::init_user();
if ($PLG->dispatch('check_request', \&Links::check_request)) {
$PLG->dispatch('handle_page', \&Links::User::Page::handle);
}
The page that is displayed when I'm using the frontend of finder.cgi is in the template finder.html. If I try to insert any of the globals set in the backend of the Glinks installation, it claims that it is an 'unknown tag'.
Hopefully this provides some clarification.
Jul 31, 2015, 1:44 AM
Veteran / Moderator (18441 posts)
Jul 31, 2015, 1:44 AM
Post #4 of 15
Views: 11295
Hi,
Have you tried something more like:
use strict;
use lib '/path/to/admin';
use Links qw/$IN $DB $CFG $USER/;
use CGI::Carp qw(fatalsToBrowser);
local $SIG{__DIE__} = \&Links::fatal;
Links::init('/path/to/admin');
Links::init_user();
handle();
sub handle {
use Geo::Helpers;
my $geo = Helpers->new ('full', '/server/path/to/cgi-bin/subsection/admin/finder.conf');
$geo->Run;
}
The bits in red are important, as they tell GLinks to correctly init.
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!
Have you tried something more like:
Code:
#!/usr/local/bin/perl use strict;
use lib '/path/to/admin';
use Links qw/$IN $DB $CFG $USER/;
use CGI::Carp qw(fatalsToBrowser);
local $SIG{__DIE__} = \&Links::fatal;
Links::init('/path/to/admin');
Links::init_user();
handle();
sub handle {
use Geo::Helpers;
my $geo = Helpers->new ('full', '/server/path/to/cgi-bin/subsection/admin/finder.conf');
$geo->Run;
}
The bits in red are important, as they tell GLinks to correctly init.
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!
Jul 31, 2015, 1:59 AM
Veteran / Moderator (18441 posts)
Jul 31, 2015, 1:59 AM
Post #6 of 15
Views: 11280
Hi,
How exactly are you trying to print the templates out, in:
$geo->Run;
Using GT::Template, or Links::SiteHTML ?
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!
How exactly are you trying to print the templates out, in:
Code:
my $geo = Helpers->new ('full', '/server/path/to/cgi-bin/subsection/admin/finder.conf'); $geo->Run;
Using GT::Template, or Links::SiteHTML ?
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!
Jul 31, 2015, 2:02 AM
Novice (15 posts)
Jul 31, 2015, 2:02 AM
Post #7 of 15
Views: 11276
Looks like GT::Template
my $self = shift;
my $type = shift;
my $conff = shift;
die "Geo::Helpers->init: config file must exist!" unless ($conff && -e $conff);
$self->{config} = new Config::Simple;
$self->{config}->read($conff) || die "Geo::Helpers->init: error reading config file: " . $self->{config}->error();
$self->{place} = new Place;
$self->{eu} = {'UK' => 1};
$self->{version} = "2.259";
$self->{env} = ( $ENV{'DOCUMENT_ROOT'} =~ /(?:dev\.site\.com)/ ? 'dev' : 'prod' );
$self->log( "init: running in '" . $self->{env} . "' mode\n" );
if ($type eq 'full') {
$self->{q} = new GT::CGI;
$self->{cookie} = {};
# Create a template object using custom settings.
$self->{tf}= new GT::Template({
root => $self->{config}->param('locs.tpl_path'),
compress => 1,
});
Links::init( '/server/path/to/cgi-bin/subsection/admin' );
Links::init_user();
}
$self->{cache} = new Cache (
config => $self->{config},
DB => $DB,
);
my $key = ( $self->{env} eq 'dev'
? $self->{config}->param( 'google.key_dev' )
: $self->{config}->param( 'google.key_prod' ) );
$self->{google} = new Google(config => $self->{config},
tf => $self->{tf},
q => $self->{q},
key => $key
);
}
Code:
sub init { my $self = shift;
my $type = shift;
my $conff = shift;
die "Geo::Helpers->init: config file must exist!" unless ($conff && -e $conff);
$self->{config} = new Config::Simple;
$self->{config}->read($conff) || die "Geo::Helpers->init: error reading config file: " . $self->{config}->error();
$self->{place} = new Place;
$self->{eu} = {'UK' => 1};
$self->{version} = "2.259";
$self->{env} = ( $ENV{'DOCUMENT_ROOT'} =~ /(?:dev\.site\.com)/ ? 'dev' : 'prod' );
$self->log( "init: running in '" . $self->{env} . "' mode\n" );
if ($type eq 'full') {
$self->{q} = new GT::CGI;
$self->{cookie} = {};
# Create a template object using custom settings.
$self->{tf}= new GT::Template({
root => $self->{config}->param('locs.tpl_path'),
compress => 1,
});
Links::init( '/server/path/to/cgi-bin/subsection/admin' );
Links::init_user();
}
$self->{cache} = new Cache (
config => $self->{config},
DB => $DB,
);
my $key = ( $self->{env} eq 'dev'
? $self->{config}->param( 'google.key_dev' )
: $self->{config}->param( 'google.key_prod' ) );
$self->{google} = new Google(config => $self->{config},
tf => $self->{tf},
q => $self->{q},
key => $key
);
}
Jul 31, 2015, 2:08 AM
Veteran / Moderator (18441 posts)
Jul 31, 2015, 2:08 AM
Post #8 of 15
Views: 11277
I seem to remember you have to actually define the globals manually, when using GT::Template
So maybe , when parsing a template with parse() / parse_print(), try also passing this new var into it:
then pass in %globals as one of the params you pass into GT::Template when actually *parsing* the template (not the bit of code you showed above)
Totally stabbing in the dark - as its hard to know without seeing your full code :)
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!
So maybe , when parsing a template with parse() / parse_print(), try also passing this new var into it:
Code:
my %globals = $Links::GLOBALS ? map { $_ => 1 } keys %$Links::GLOBALS : ();then pass in %globals as one of the params you pass into GT::Template when actually *parsing* the template (not the bit of code you showed above)
Totally stabbing in the dark - as its hard to know without seeing your full code :)
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!
Jul 31, 2015, 2:17 AM
Novice (15 posts)
Jul 31, 2015, 2:17 AM
Post #9 of 15
Views: 11280
This is the parse sub in the for the Geo package:
sub parse {
my( $self, $tpl, $vars ) = @_;
print $self->cgi->header;
# Don't complain if $vars was undef
$vars = {} if !( defined( $vars ) );
$vars->{'version'} = $self->{version};
eval {$self->{tf}->parse_print( $tpl, { %$vars } )};
if( $@ ) {
$self->log( "$0: error in parse_print(): '$@'\n" );
$self->{tplErr} = $@;
return 0;
} else {
return 1;
}
}
Would this be the correct edit?
sub parse {
my( $self, $tpl, $vars ) = @_;
print $self->cgi->header;
my $globals = $Links::GLOBALS ? map { $_ => 1 } keys %$Links::GLOBALS : ();
# Don't complain if $vars was undef
$vars = {} if !( defined( $vars ) );
$vars->{'version'} = $self->{version};
$vars->{'globals'} = $globals; #edit
eval {$self->{tf}->parse_print( $tpl, { %$vars } )};
if( $@ ) {
$self->log( "$0: error in parse_print(): '$@'\n" );
$self->{tplErr} = $@;
return 0;
} else {
return 1;
}
}
Code:
sub parse {
my( $self, $tpl, $vars ) = @_;
print $self->cgi->header;
# Don't complain if $vars was undef
$vars = {} if !( defined( $vars ) );
$vars->{'version'} = $self->{version};
eval {$self->{tf}->parse_print( $tpl, { %$vars } )};
if( $@ ) {
$self->log( "$0: error in parse_print(): '$@'\n" );
$self->{tplErr} = $@;
return 0;
} else {
return 1;
}
}
Would this be the correct edit?
Code:
sub parse {
my( $self, $tpl, $vars ) = @_;
print $self->cgi->header;
my $globals = $Links::GLOBALS ? map { $_ => 1 } keys %$Links::GLOBALS : ();
# Don't complain if $vars was undef
$vars = {} if !( defined( $vars ) );
$vars->{'version'} = $self->{version};
$vars->{'globals'} = $globals; #edit
eval {$self->{tf}->parse_print( $tpl, { %$vars } )};
if( $@ ) {
$self->log( "$0: error in parse_print(): '$@'\n" );
$self->{tplErr} = $@;
return 0;
} else {
return 1;
}
}
Jul 31, 2015, 2:20 AM
Veteran / Moderator (18441 posts)
Jul 31, 2015, 2:20 AM
Post #10 of 15
Views: 11263
Yeah, that should work. Again, I'm stabbing in the dark - never had to do it quite this way before (generally I do it using Links::SiteHTML, where the globals are included as standard)
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!
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!
Jul 31, 2015, 2:43 AM
Veteran / Moderator (18441 posts)
Jul 31, 2015, 2:43 AM
Post #12 of 15
Views: 11262
Hi
Mmm ok.
Where is the path pointing to here?
If locs.tpl_path is inside the glinks /admin/templates/folder/ structure, then you could pretty easily use Links::SiteHTML to do it. AFAIK, Links::SiteHTML::display doesn't allow you to pass in a root => xxx value like you can in GT::Template - so you would need it to be in the main template folder (and then link it via a .tplinfo file if you wanted to have it in another folder)
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!
Mmm ok.
Where is the path pointing to here?
Code:
root => $self->{config}->param('locs.tpl_path'),If locs.tpl_path is inside the glinks /admin/templates/folder/ structure, then you could pretty easily use Links::SiteHTML to do it. AFAIK, Links::SiteHTML::display doesn't allow you to pass in a root => xxx value like you can in GT::Template - so you would need it to be in the main template folder (and then link it via a .tplinfo file if you wanted to have it in another folder)
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!
Aug 12, 2015, 1:21 AM
User (435 posts)
Aug 12, 2015, 1:21 AM
Post #14 of 15
Views: 10976
Hi,
I might be wrong, but I guess you could use:
http://www.gossamer-threads.com/...ing=%20STASH#p310637
I am very happy with this solution, you can add global values for templates and scripts.
Regards
n||i||k||o
I might be wrong, but I guess you could use:
http://www.gossamer-threads.com/...ing=%20STASH#p310637
I am very happy with this solution, you can add global values for templates and scripts.
Regards
n||i||k||o
Aug 12, 2015, 7:41 AM
User (435 posts)
Aug 12, 2015, 7:41 AM
Post #15 of 15
Views: 10945
Ah, sorry, what I forgot is this part:
. Links::template_set()
. "/globals.txt", {
inheritance => 1,
compile_subs => 'Links',
local => 1
});
where you can replace the template set Links::template_set() with luna if you only use luna.
Code:
my $GLOBALS = GT::Config->load("$CFG->{admin_root_path}/templates/" . Links::template_set()
. "/globals.txt", {
inheritance => 1,
compile_subs => 'Links',
local => 1
});
where you can replace the template set Links::template_set() with luna if you only use luna.