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


In reply to Multiple FOREACH loops in a MIME::Lite::TT template by stevieb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.