pileofrogs has asked for the wisdom of the Perl Monks concerning the following question:
Blessings upon ye, Monks of Perl.
I recently embarrassed myself by asking TT & templates from data?. And here is another, hopefully less stupid question:
Is there a way to make Template::Toolkit process the contents of a variable inside of a template?
E.G.
my $vars = { header => 'hello, [% name %]', footer => 'goodbye, [% name %]', name => 'Dave', } my $template = <<"END"; [% header %] I'm afraid I can't do that [% footer %] END my $TT = Template->new(); my $output; $TT->process(\$template,$vars,\$output) || die $TT->error();
If "header" and "footer" were external files, I could INCLUDE them, but they are scalars.
I was able to make it work by running process twice:
$TT->process(\$template,$vars,\$output) || die $TT->error(); $TT->process(\$output,$vars,\$output) || die $TT->error();
But I'd rather do something less kludgey and more scalable.
Thanks for any ideas!
--Pileofrogs
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Yet Another Stupid TT Question
by perrin (Chancellor) on Dec 12, 2008 at 21:50 UTC | |
by pileofrogs (Priest) on Dec 12, 2008 at 22:05 UTC | |
by ikegami (Patriarch) on Dec 12, 2008 at 22:52 UTC | |
by perrin (Chancellor) on Dec 12, 2008 at 23:30 UTC | |
by ikegami (Patriarch) on Dec 13, 2008 at 00:13 UTC | |
|
Re: Yet Another Stupid TT Question
by jeffa (Bishop) on Dec 12, 2008 at 21:17 UTC | |
|
Re: Yet Another Stupid TT Question
by ikegami (Patriarch) on Dec 12, 2008 at 21:21 UTC | |
by pileofrogs (Priest) on Dec 12, 2008 at 21:27 UTC | |
by ikegami (Patriarch) on Dec 12, 2008 at 21:33 UTC |