12.17.2005

HTML::Template and MySQL/DBI


#!/usr/bin/perl -w

use strict;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
use HTML::Template;
use DBI;

# database connection code

my $template;
my $newtemplate;
my $minitemplate;
my $query = new CGI;
my $sth;

$template = HTML::Template->new(
filename => "template.tmpl"
);

# this line would contain the prepare for a SELECT statement that
would return the mini-template we would be using.
$sth->execute();
$newtemplate = $sth->fetch;

$minitemplate = HTML::Template->new(
arrayref => $newtemplate
);

$minitemplate->param(test => "toost");

$template->param(content => $minitemplate->output);

print $query->header();
print $template->output;

No comments: