[Templates] assigning to scalar passed as scalar reference
Rodney Broom
rbroom+tt2 at rbroom.com
Wed Jul 9 14:01:59 BST 2008
Yes, thank you both. I thought that Template::Stash copying prevented this, but hadn't tried.
My first use for this will be to put my canned-email subjects into the templates where they belong rather than in the code.
$vars{stuff} = {};
$tt->process($tmpl, \%vars, \$content);
send_email(body => $content, subject => $vars{stuff}->{subject})
---
Rodney Broom
----- Original Message -----
From: "Lee.M" <jupiter at jupiterhost.net>
To: <templates at template-toolkit.org>
Sent: Tuesday, July 08, 2008 13:05
Subject: Re: [Templates] assigning to scalar passed as scalar reference
> thanks Jason, good idea!
>
> On Jul 8, 2008, at 2:48 PM, Jason Gottshall wrote:
>
>> Lee.M wrote:
>>> I want to do this:
>>>
>>> my $var = '';
>>>
>>> $tt->process($tmplt, { var => \$var}, $out);
>>>
>>> print "var is now $var\n"; # var is now new value
>>>
>>> and allow the template to set its value
>>
>> Pass a known hashref of template variables, instead of an anonymous
>> one,
>> and you can refer to it later:
>>
>> my %variables = ();
>> $variables{var} = '';
>>
>> $tt->process($tmplt, \%variables, $out);
>>
>> # $tmplt contains:
>> # [% var = 'new value' %]
>>
>> print "var is now $variables{var}\n"; # var is now 'new value'
>>
>> HTH,
>> Jason
>>
>>
>> _______________________________________________
>> templates mailing list
>> templates at template-toolkit.org
>> http://mail.template-toolkit.org/mailman/listinfo/templates
>
>
> _______________________________________________
> templates mailing list
> templates at template-toolkit.org
> http://mail.template-toolkit.org/mailman/listinfo/templates
>
More information about the templates
mailing list