Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Accessing the stash within a TT file

by thunders (Priest)
on Jun 30, 2009 at 18:04 UTC ( [id://776128]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://776128]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2026-02-07 17:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.