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

using templates.pm

Quote Reply
using templates.pm
Hi,

I am very interested in using the Templates.pm for other scripts. From what I understand, this is the only item I should need?

And when I call to load a template, lets say "test.html", from my cgi script, I must call on the sub load_template
correct?

I have glanced over the subs in HTML_Templates.pm, but I am stumped. What format should I use when calling to load template "test.html" into a program?

Would it go something like this:

my $output = &load_template ('test.html', { $scalars $needed $to_be_parsed }, undef, $template);
defined $dynamic and &clean_output($dynamic, \$output);
print $output;

Any help would be appreciated.
Thanks.

Robert Blackstone
Webmaster of Scato Search
http://www.scato.com
Quote Reply
Re: using templates.pm In reply to
('cool.html', {
%$tags,
%GLOBALS
}, undef, $template );

If you look through the HTML_Templates.pm file, the basic format of the &load_template call is:

('template.html', {hash}, undef, $template}

You need to pass a template file to load, a hash of values to make available to the template (remember, {%hash1, %hash2, key=>$value} is all flattened to one hash when passed, and I really am not sure what 'undef' does, except act as a terminator field, and then $template is the path to templates.

HTML_Templates.pm is really a wrapper file for the &load_template call, where each specific subroutine adds extra data to the {hash} values that are passed.

While Templates.pm doesn't 'use' or 'require' any other modules, I don't know if it is dependent on any of the set up information or not. I've never tried to use it stand-alone.


http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: using templates.pm In reply to
Hi pugdog,

Thanks for your help! I did figure out a way to do this using MysqlMan, that is where I found the GT_Template.pm and GT_Base.pm files. Here is what I did, just in case if anyone else is interested.

First I created a file called "temp.html", which included these lines:

<%scalar1%>
<P>
<%scalar2%>
<P>
<%scalar3%>

Then I created a script called "test.cgi", which looked like this:

#!/usr/bin/perl5.004

use CGI; # This is a CGI program.
use DBI; # Will let us access the database.
use CGI::Carp qw/fatalsToBrowser/; # Trap any errors.

require "GT_Template.pm";

# Print out the HTML headers.
print CGI->header();

$scalar1 = "golf ball";
$scalar2 = "basketball";
$scalar3 = "soccer camp";

print GT_Template->parse ("temp.html", {
scalar1 => $scalar1 || '',
scalar2 => $scalar2 || '',
scalar3 => $scalar3 || '',

});

And for the sake of keeping it simple, I placed all 4 of these files in the same directory:

temp.html
test.cgi
GT_Base.pm
GT_Template.pm

You get the idea. Hope that helps everyone else. :)



Robert Blackstone
Webmaster of Scato Search
http://www.scato.com