Would something simple like this work for you?
## BEGIN CODE
use strict;
my $template = new MyTemplate (
INCLUDE_PATH => [
'path1/here',
'path2/here',
'etc/etc/etc'
]
);
my $file = 'index.html';
if (my $path = $template->exists ($file)) {
print "$file exists in $path\n";
} else {
print "$file does not exist\n";
}
exit;
package MyTemplate;
use strict;
use Template;
use base qw( Template );
sub exists {
my $self = shift;
my $file = shift or return;
my $include_path = $self->context->load_templates->[0]->include_path;
return unless ref $include_path eq 'ARRAY';
foreach my $path (@$include_path) {
return $path if -e "$path/$file";
}
}
1;
## END CODE
Peter Guzis
Web Administrator, Sr.
ENCAD, Inc.
- A Kodak Company
email: [EMAIL PROTECTED]
www.encad.com
-----Original Message-----
From: Bradley Baetz [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 18, 2003 1:07 AM
To: [EMAIL PROTECTED]
Subject: [Templates] Discovering if a template exists
Is there an easy way to discover if a template exists? Bugzilla allows a
page in various formats and content types, which we basically append to
the template name. Currently, we only give the generic 'file not found'
message from TT, displayed as a Bugzilla internal error, but we want ot
detect this at the start of the script and error out gracefully.
Template::Context->template doesn't work because I'd have to parse the
error message for the 'file not found' error text, which seems a bit
fragile.
Currently I'm just iterating over $template->context->{LOAD_TEMPLATES}.
That works fine, but it misses out on some of the logic in
$template->context->template(). Bugzilla doesn't actually use any of the
extra stuff, but it would be nice if there was a more generic/supported
way to do this.
Bradley
_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates
_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates