http://www.perlmonks.org?node_id=776128


in reply to Accessing the stash within a TT file

Yes, you can directly acess the stash from a PERL block.
use Template; my $tt = Template->new({EVAL_PERL => 1}); my $vars = { x => [1,2,3] }; my $text = q{ [%PERL%] use Data::Dumper; print STDOUT Dumper $stash [%END%] }; $tt->process(\$text,$vars);
output:
$VAR1 = bless( { 'template' => bless( { '_DEFBLOCKS' => {}, '_BLOCK' => sub { "DUMMY" }, 'modtime' => 1246384891, 'name' => 'input text', '_HOT' => 1 }, 'Template::Document' ), 'global' => {}, 'inc' => sub { "DUMMY" }, 'x' => [ 1, 2, 3 ], 'dec' => sub { "DUMMY" }, 'component' => $VAR1->{'template'}, '_DEBUG' => 0, '_PARENT' => bless( { 'global' => $VAR1->{'global'}, 'inc' => $VAR1->{'inc'}, '_DEBUG' => 0, 'dec' => $VAR1->{'dec'}, '_PARENT' => undef }, 'Template::Stash::XS' ) }, 'Template::Stash::XS' );

Replies are listed 'Best First'.
Re^2: Accessing the stash within a TT file
by thunders (Priest) on Jun 30, 2009 at 18:17 UTC

    That being said, what exactly are you trying to do? It's already possibly to PROCESS a file from another TT file. Is there something specific you need to do that PROCESS does not do?

    If you simply need to modify existing stash variables, or add new stash variables, you could probably get away with a TT wrapper file that manipulates variables and then calls PROCESS on another tt file supplied as an argument.

Re^2: Accessing the stash within a TT file
by Anonymous Monk on Jul 01, 2009 at 01:02 UTC