Well, I'm torn on this. I totally agree this sounds very sensible. Do the crunching in the Perl script.

But at the same time, this use of TT just seems custom made for my application, with th epossible exception of this last outrageous desire. I mean, imagine, you've got data that looks like

year x 5
- class x 3
--- sub-class x 5
----- data rows x 50

This just screams for

$data{$year}{$class}{$sub-class}{row-element-i} = 'foo';
and then
<table> [% FOREACH year IN data.keys.sort %] <tr><td colspan=x>Year [% year %]</td></tr> [% FOREACH class IN data.$year.keys.sort %] <tr><td>spacer</td><td colspan=x-1>Class [% class %]</td></tr> [% FOREACH sub-class IN data.$year.$class.keys.sort %] <tr><td colspan=2>spacer</td><td colspan=x-2>Sub-Class [% sub +-class %]</td></tr> <tr> [% FOREACH element IN data.$year.$class.$sub-class.keys.sort +%] <td>[% data.$year.$class.$sub-class.$element %]</td> [%END%] </tr> [%END%] [%END%] [%END%] </table>
and, bing!, you're done, with the data generation completely dissociated from the layout generation.

This is the kind of power that made me fall in love with TT.

My alternative - or at least the only one of which I'm aware, would be to do all that html generation inside the Perl script and export $data_table_html_string to the template.


In reply to Re^2: Reverse sort order in FOREACH in Template Toolkit by punch_card_don
in thread Reverse sort order in FOREACH in Template Toolkit by punch_card_don

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.