Dennis Daupert:
> I just found the solution in the tt archive. The discussion on
> Interpolating tags within tags aplies here too. I just piped
> my variable holding the email body template thru eval,
> and it works great. Thanks, guys!
>
> [% tmpl.body | eval %]
May I suggest another way to do things? This is a template class that directly
reads templates from the database, so you don't have to mess with the DBI
plugin. It's somewhat abridged from the original Feuilleton::View class, which
you can find by Googling.
sub template {
my ($self, $template, $template_args, $output) = @_;
my $template = Template->new({
LOAD_TEMPLATES => [Database::Provider->new()]
});
my $output;
if ($template->process($template, $template_args, \$output)) {
return 1;
} else {
return $template->error;
}
}
package Database::Provider;
use base qw( Template::Provider );
sub content {
my ($self, $name) = @_;
my ($template) = Database::Template->search( name => $name );
# Database::Template is a Class::DBI class relating to a table which has two
# fields, name and content. Having searched based on the name, we now want
# to get the content.
if ($template) { return $template->content; }
return undef;
}
sub fetch {
my ($self, $name) = @_;
my ($data, $error);
# ref to scalar means we've been passed the template
return $self->SUPER::fetch($name) if (ref $name eq 'SCALAR');
$name = $name->name if ref($name);
($data, $error) = $self->_load($name, undef);
($data, $error) = $self->_compile($data, undef) unless $error;
if ($error) {
$data = "DB template \"$name\" - ".$data;
} else {
$data = $data->{ data };
}
return($data, $error);
}
use Template::Constants;
sub _load {
my ($self, $name, $text) = @_;
return $self->SUPER::_load($name, $text) if (ref($name) || !$name);
my $content = $self->content($name);
return ("Can't find template '$name' in DB",
Template::Constants::STATUS_DECLINED())
unless defined($content);
my $data = { name => $name, text => $content, time => time, load => 0, };
return ($data, undef);
}
1;
--
<Addi> Just imagine we are meeting the aliens for the first time.
<ton> Most people would just shoot them to see how many points they are
worth.
_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates