Re: Using a "hash" as a Template::Provider

Andy Wardley <[email protected]> Fri, 15 Mar 2013 06:19:33 +0000
Newsgroups gmane.comp.lang.perl.modules.template-toolkit
Message-ID <[email protected]>
On 15/03/2013 01:13, Philippe Bruhat (BooK) wrote:
> My question is: did I overlook a simpler way to do this?

You can use the BLOCKS configuration item to define templates up front:

   http://template-toolkit.com/docs/manual/Config.html#section_BLOCKS

e.g.

   my $tt = Template->new(
       BLOCKS => {
           t1 => '[% INCLUDE t2 %]',
           t2 => '[% foo %]',
       }
   );

   $tt->process(\"t1: [% INCLUDE t1 %]", { foo => 3.14 })
       || die $tt->error;


Cheers
A