Re: Accessing template variables after process

"Daniel Degenhardt" <[email protected]> Wed, 20 Jun 2012 10:31:27 +0200
Newsgroups gmane.comp.lang.perl.modules.template-toolkit
Message-ID <[email protected]>
Thanks for the really quick response. 

Still it seems that I'm missing something essential. If I do it the way you explained, I always get the unmodified values:

[% name="John" %]

in the template still results in printing "Fred" if I write

print $stash{name};


-------- Original-Nachricht --------
> Datum: Tue, 19 Jun 2012 23:35:10 -0400
> Von: Clayton Scott <[email protected]>
> An: Daniel Degenhardt <[email protected]>
> CC: [email protected]
> Betreff: Re: [Templates] Accessing template variables after process

> On Tue, Jun 19, 2012 at 5:56 PM, Daniel Degenhardt
> <[email protected]>wrote:
> 
> > Hello,
> >
> > is there a way to access the (modified) template variables from perl
> > script after calling process? The reason I like to do that, is that I
> want
> > to set the output filename from within the template file. Something like
> > that:
> >
> > [% filename = "$somevar.$someextension" %]
> >
> >
> Sure, I've done this a lot. You can modify the variables passed in, I
> always find it easiest to do it this way:
> 
> my %stash = ( name => 'Fred',  email => '[email protected]', headers =>
> {});
> 
> my $output;
> 
> $tt->process($template, \%stash, \$output);
> 
> sendmail( to => $stash{email}, subject => $stash{headers}{subject}, body
> =>
> $output );
> 
> 
> -- somewhere in a template --
> 
> [% headers.subject = name _ ', special on brontosaurus burgers' %]
> 
> [% name %], come on down to the Drive-In and get 2 for 1 bronto burgers
> 
> Sincerely,
> The Management
> 
> 
> This code/ template are untested,
> Clayton
> 
> 
> > From perl i like to read out the filename variable and save the
> > instantiated template file under that name.
> >
> > Any hints welcome!
> >
> > Thanks in advance,
> >
> > Daniel.
> > _______________________________________________
> > templates mailing list
> > [email protected]
> > http://mail.template-toolkit.org/mailman/listinfo/templates
> >
> 
> 
> 
> -- 
> 
> Clayton Scott
> [email protected]

-- 
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de