[Templates] Getting at template variables outside of a template

Andy Wardley abw@wardley.org
Fri, 14 Sep 2007 07:15:33 +0100


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
    %]

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.

Cheers
A