Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

grand_total as a Global

Quote Reply
grand_total as a Global
Would anyone know how to make <%grand_total%> as a global variable in HTML_Templates. I had it going but didn't work with add.cgi.

This is what I tried. It worked on every page except add.cgi,

I added this to the top of HTML_Templates.pm

my ($LINKDB,$sth,$total,$GRAND_TOTAL);

$LINKDB = new Links: BSQL "$LINKS{admin_root_path}/defs/Links.def";

$sth = $LINKDB->prepare ("SELECT COUNT(*) FROM CategoryAlternates");
$sth->execute();
($total) = $sth->fetchrow_array;
$GRAND_TOTAL = $LINKDB->total();


%GLOBALS = (
date => \&Links: BSQL::get_date,
time => \&Links: BSQL::get_time,
db_cgi_url => $LINKS{db_cgi_url},
build_root_url => $LINKS{build_root_url},
site_title => $LINKS{build_site_title},
css => $LINKS{build_css_url},
banner => '',
grand_total => $GRAND_TOTAL

);


Any ideas?

Thanks,

Kevin
Quote Reply
Re: grand_total as a Global In reply to
In the add.cgi, in the sub main ()

You need to add:

Code:

my ($GLOB_LINKDB,$GRAND_TOTAL);
$GLOB_LINKDB = new Links: BSQL "$LINKS{admin_root_path}/defs/Links.def";
$GRAND_TOTAL = $GLOB_LINKDB->total();

Right before the first test loop.

Then, you want to make the call to the template routine:

Code:
&site_html_add_form ({ Category => $category, grand_total=> $GRAND_TOTAL, %in }, $dynamic)


The HTML_Templates.pm file does _NOT_ include or use the DBSQL.pm module, so there is no way to call the ->total() method.

The <%grand_total%> is calculated in nph_build.cgi which is why it's not available to scripts that don't use nph_build.cgi to call html_templates.pm.

This is the _best_ way to do it. There are some really good logic reasons why you should not calculate anything in the HTML_Templates.pm file except random numbers, and variable substitutions that are added to the %GLOBALS hash.

"grand_total" is something that should be calculated by your script, and passed to the HTML_Templates.pm file.