in reply to Yet Another Stupid TT Question

If you had two templates, you could do

layout:

<p>hello, [% name %] [% content %] <p>goodbye, [% name %]

somepage:

<title>Some Page</title> [% WRAPPER layout %] <p>This is the body of the page. [% END %]

Process "somepage".

Replies are listed 'Best First'.
Re^2: Yet Another Stupid TT Question
by pileofrogs (Priest) on Dec 12, 2008 at 21:27 UTC

    Except the whole point is that I don't. I've got some dynamically generated text that may include more TT markup, which may itself include more TT markup. That's not a problem if the text resides in a text file, but it doesn't seem to work if it lives in a scalar. That seems odd to me.

      Re: Template Toolkit Cache should do the trick. It allows templates to be read from memory instead of from disk.

      Update: Some code:

      use Template qw( ); use Template::Provider::Memory qw( ); my %mem_drive = ( 'layout' => [ time(), <<'__EOI__' ], <p>hello, [% name %] [% content %] <p>goodbye, [% name %] __EOI__ 'somepage' => [ time(), <<'__EOI__' ], <title>Some Page</title> [% WRAPPER layout %] <p>This is the body of the page. [% END %] __EOI__ ); my $tt = Template->new({ LOAD_TEMPLATES => [ Template::Provider::Memory->new({ MEM_DRIVE => \%mem_drive }), Template::Provider->new(), ], }); my $vars = { name => 'Dave', }; my $output; $tt->process('somepage', $vars) or die($tt->error(), "\n");

      The module and the var need a better name.