xslate icon indicating copy to clipboard operation
xslate copied to clipboard

using vars as a template cache

Open thishitshome opened this issue 7 years ago • 1 comments

In template frameworks like Template::Alloy (Toolkit) and Jinja2, you can use "vars" like a cache where the variables you set in a template are updated into the object.

I am wondering if this project provides a similar mechanism. I haven't been able to accomplish it from what I've tried so far.

An example using Template::Alloy would be like this:

#!/usr/bin/env perl
use Template::Alloy;
use Data::Dumper;

my $t = Template::Alloy->new();
my $template = "[% hair = 'Brown' %]";
my $vars = {
    name => 'Alice'
};
my $out;

$t->process_simple(\$template, $vars, \$out);

print Dumper $vars;

You can see that the 'hair' variable that was set in the template is now included in the $vars hash.

$ perl ./example.pl
$VAR1 = {
          'name' => 'Alice',
          'hair' => 'Brown'
        };

thishitshome avatar Apr 09 '18 17:04 thishitshome

It's been a while, but I don't think I ever wrote a feature like that.

lestrrat avatar Apr 09 '18 20:04 lestrrat