[Templates] Getting at template variables outside of a template

Mark Wagner Mark Wagner <markwag@u.washington.edu>
Thu, 13 Sep 2007 17:36:45 -0700


I have a configuration template "host.cfg" that has something like this
in it:

[%~

ip = '10.0.0.0'

~%]

When I process a template info.tt:

My IP is [% ip %]

I load the config using PRE_PROCESS:

my $tt = Template->new({'PRE_PROCESS' => 'host.cfg' });

$tt->process("info.tt");

Everything is fine. However, I wish to access the value of
"ip" outside a template. I thought I could access "ip" via the stash
like so:

my $tt = Template->new();
$tt->process('host.cfg');

print $tt->context()->stash()->get('ip'), "\n";

Alas, this doesn't work.

Is there a way to do this?

Thanks,

Mark

-- 
Mark Wagner <markwag@u.washington.edu>
System Administrator, UW Medicine IT Services
206-616-6119