On Fri, Sep 14, 2007 at 07:15:33AM +0100, Andy Wardley wrote:
> Mark Wagner wrote:
> >Is there a way to do this?
> 
> Not easily.  You can hack it by passing a hash ref into your process() 
> method which the template can update.
> 
>    my $export = { };
>    $tt->process("info.tt", { export => $export });
>    print $export->{ ip };    # 10.0.0.0
> 
> And in the template:
> 
>    [% ip = '10.0.0.0';
>       export.ip = ip
>    %]

Why does the Template::Stash get gutted after the the process?

I tried this hack:

$config->{'export'} = { };
$hack = '[% PERL %] $stash->set([ "export", 0, "stash", 0 ], $stash); [% END 
%]';
$tt->process(\$hack, $config));

Then outside the template $config->{'export'}{'stash'} is a
Template::Stash with all the data.

I read Template::Manual::Internals and tried looking through the Template
code to figure out what is going on to no avail.

I also came up with the hack using Data::Dumper on the stash in a
[% PERL %] block, sending the template output to a string, and evaling
it but IMHO that is getting obscene.

> However, my tingling spider sense tells me that you should probably extract 
> the information out into a YAML file, Perl module, or some other data 
> source which you can easily use from both TT and other apps.

Thanks, I'll look into that.

-- 
Mark Wagner <[EMAIL PROTECTED]>
System Administrator, UW Medicine IT Services
206-616-6119

_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to