stevieb has asked for the wisdom of the Perl Monks concerning the following question:
Most gracious and wise Monks, I'm confident that I'm simply overlooking something simple, but I thought I'd get back to another task while I attempt to acquire help with this tiny issue.
Within a project of mine, I'm dealing with three different templating systems. Two of which I have no problem throwing an aref of hrefs that contain arefs of hrefs and have it convert it to multi-nested loops. One, as documented in the Subject, requires an href passed in, and I can't quite figure out how to extract multiple loops out of it. For brevity sakes, imagine these two lines within an if/else:
push @notices, { username => $username, hours => $hours_balance, }; push @renewals, { username => $username, hours => $hours_balance, };
...then this a bit later:
my %sent; $sent{ notices } = \@notices; $sent{ renewals } = \@renewals;
...I then (essentially) throw \%sent toward the mailer.
My template (which I've tried moving around the %END% to no avail) looks like this:
Clients sent Notices: [% FOREACH item IN notices %] [%item.username%]: [%item.hours%] [% END %] Clients sent Renewals: [% FOREACH item in renewals %] [%item.username%]: [%item.hours%] [% END %]
The email that I receive as a result prints out both sections, but the 'Renewals' section contains the last entry from 'Notices' twice, which is incorrect, and inconsistent with what I get from Dumper. Notices are >=10 and <= 15, where Renewals are anything else (ie. < 10).
Can someone point out where my looping logic in the template is wrong? Here's a snip of a Dumper output:
$VAR1 = { 'renewals' => [ { 'hours' => '8.84 hours remaining', 'username' => 'airdhill' }, { 'hours' => '5.51 hours remaining', 'username' => 'anneli' }, { 'hours' => '4.97 hours remaining', 'username' => 'batelaan' }, { 'hours' => '8.21 hours remaining', 'username' => 'bc' }, { 'hours' => '9.24 hours remaining', 'username' => 'bmcadam' }, ], 'notices' => [ { 'hours' => '13.17 hours remaining', 'username' => 'abrayman' }, { 'hours' => '10 hours remaining', 'username' => 'alsminor' }, { 'hours' => '14.24 hours remaining', 'username' => 'anreed' }, { 'hours' => '15 hours remaining', 'username' => 'ashwood' }, { 'hours' => '10 hours remaining', 'username' => 'bassman' }, ] };
Since Dumper writes out the correct data to STDOUT, I'm thinking that I'm not passing the data to the module correctly. Extra XP goes to anyone who can point out my err (jk), or is this a case where I need to follow the source of the module upwards?
More code will be provided if needed.
-sb
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Multiple FOREACH loops in a MIME::Lite::TT template
by stevieb (Canon) on Jun 29, 2010 at 02:07 UTC | |
by planetscape (Chancellor) on Jun 29, 2010 at 02:58 UTC | |
by stevieb (Canon) on Jun 29, 2010 at 03:15 UTC |