Gossamer Forum
Home : General : Perl Programming :

Re: [TheSafePick] HTML::Template

Quote Reply
Re: [TheSafePick] HTML::Template In reply to
Like Dan already mentioned it doesn't matter where images are (besides the cgi-bin) so long as you use a absolute path instead of a relative path. I always put my templates above the doc root and just set the path in H::T accordingly. If you have templates in more than one path H::T will take an arrayref to the path arg to accommodate. Here is something close to what I do. I use CGI::Application so it's not exact but it gives you an idea:

Code:
sub load_tmpl {
my ($self, $tfile, $args) = @_;

# default param set for the templates
$args ||= {};

# Create our template object
require HTML::Template;
my $t = HTML::Template->new(filename => $tfile,
# Add all your paths here
path => ['/path/to/templates',
'/alternate/path'],
# Associate on objects. I usually associate
# my CGI object by default. ymmv.
#associate => $self->query,

# The usual defaults here:
die_on_bad_params => 0,
loop_context_vars => 1,
global_vars => 1,
);
$t->param(%$args);
return $t;
}

# Then when you need a template object:

my $t = $self->load_tmpl('my_file.tmpl', { some => 'more args here'});
print $t->output;

# And if the template is in a subdir of one of your paths:
my $t = $self->load_tmpl('sub_dir/my_file.tmpl', { some => 'more args here'});
print $t->output;

# or even shorter:
print $self->load_tmpl('my_file.tmpl', { some => 'more args here'})->output;

~Charlie
Subject Author Views Date
Thread HTML::Template TheSafePick 6288 Oct 28, 2004, 8:06 PM
Thread Re: [TheSafePick] HTML::Template
dan 6105 Oct 28, 2004, 8:42 PM
Thread Re: [dan] HTML::Template
TheSafePick 6098 Oct 29, 2004, 6:48 AM
Post Re: [TheSafePick] HTML::Template
dan 6088 Oct 29, 2004, 10:15 AM
Post Re: [TheSafePick] HTML::Template
Chaz 6088 Oct 29, 2004, 10:37 AM
Post Re: [TheSafePick] HTML::Template
TheSafePick 6066 Oct 31, 2004, 4:36 AM