Hey all,
To clarify the problem that I am posing, here is a more legible view of
the code:
---------
use strict;
use warnings;
use Template;
use Template::Stash;
my $tt2 = 'Hi. [% FOR key = x.keys(); "Key $key"; END %]';
my $data = { x => {
a => 2,
b => 3,
keys => [4,5,6],
} };
Template->new()->process(\$tt2, $data);
---------
I don’t see an RT about this....has there been discussion of this before?
-FG
Felipe Gasper (cPanel) wrote on 27 Oct 2010 14:56 ...
> If I have:
>
> perl -MTemplate -MTemplate::Stash -le
> 'Template->new({STASH=>Template::Stash->new()})->process(\"Hi. [%
> FOREACH key IN x.keys() %]Key [% key %], [% END
> %]",{x=>{a=>2,b=>3,keys=>[4,5,6]}});'
>
> ...one would think, not being familiar with TT, that “x.keys()” is a
> method call.
>
> As many of us know, though, TT looks first at the “keys” item of the “x”
> hash.
>
> Even if you do “x.keys(1)”, TT will still treat this as a hash lookup.
>
> It’s not too difficult to teach Template::Stash how to regard the “1”
> argument as an explicit request for a method; however, getting it to
> treat “.keys()” as a method, when there is a “keys” item in the hash, is
> a taller order that appears to require altering Parser.yp.
>
> Has anyone had experience with this? Might there possibly be an RT case
> about this already?
>
> -FG
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates