I wrote HTML::Template::Plugin::Dot, and I'm pretty sure this ought to work. See the t/dot_loop.t test in the distribution. I'll paste it here verbatim:
use Test::More qw(no_plan); use strict; use_ok('HTML::Template::Pluggable'); use_ok('HTML::Template::Plugin::Dot'); use_ok('Test::MockObject'); my $mock = Test::MockObject->new(); $mock->mock( 'some', sub { $mock } ); $mock->mock( 'method', sub { "chained methods work inside tmpl_loop" } + ); my $mock2 = Test::MockObject->new(); $mock2->mock( 'some', sub { $mock2 } ); $mock2->mock( 'method', sub { "chained methods work inside a loop twic +e" } ); my ($output, $template, $result); $template = qq{<tmpl_loop deloop><tmpl_var num><tmpl_var should_be.som +e.method></tmpl_loop>}; # test a simple template my $t = HTML::Template::Pluggable->new( scalarref => \$template, debug => 0 ); eval { $t->param('deloop',[ {should_be => $mock, num => 1}, {should_be => + $mock2, num => 2} ]); $output = $t->output; }; SKIP: { skip "HTML::Template subclassing bug for tmpl_loop support. See: h +ttp://rt.cpan.org/NoAuth/Bug.html?id=14037", 2 if $@; like($output ,qr/chained methods work inside tmpl_loop/); like($output ,qr/chained methods work inside a loop twice/); }
We use HT::Dot extensively in our company, in combination with CGI::Application and Class::DBI. It works okay, but I'd be the first to admit that it can't compete with the Template Toolkit. HT::Dot is limited in what it can accomplish, mainly because of the way HTML::Template itself is structured. It was easy to put some form of dot-expression parsing inside param(), but it would be very difficult to actually hook it into H::T's parsing code. If I had to muck around in there, I'd be creating a real fork of HTML::Template. And that would be futile, since TT2 is already so much better.
Rhesa
In reply to Re: HTML::Tempate::Dot
by rhesa
in thread Using loops with HTML::Template::Dot
by debiandude
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |