O Monks,

I have a database with records sorted by a category field. I want to use Template::Toolkit to get a listing with control break by category, i.e. starting from

(1, 2, A, 4) (3, 4, A, 5) (5, 5, B, 2) (6, 2, B, 3) (1, 2, C, 2) (2, 3, C, 2) (1, 3, C, 1)

where A, B, C is the record category, I want to have Template::Toolkit give me

A 1, 2, A, 4 3, 4, A, 5 B 5, 5, B, 2 6, 2, B, 3 C 1, 2, C, 2 2, 3, C, 2 1, 3, C, 1

I have managed to build a somewhat complex data structure like this

[ { cat => 'A', list => [{1, 2, A, 4},{3, 4, A, 5}]}, { cat => 'B', list => [{5, 5, B, 2},{;6, 2, B, 3}]}, { cat => 'C', list => [{1, 2, C, 2},{2, 3, C, 2},{1, 3, C, 1}]} ]

Then my TT template says something like

<% FOREACH catrec IN reclist %> <% catrec.cat %> <% FOREACH rec IN catrec.list %> <% rec %> <% END %> <% END %>

Which works as expected. Now, I feel this should be a task frequent enough so as to guarantee that TT would provide some means to accomplish it directly from the sorted tuples, without resort to the weird transformation I have done. Alas, I have perused the whole TT book by Wardley et al not to find any hint of this.

Is there some easier way to have TT graciously spit what I desire? Also, is "control break" the proper name for what I intend TT to do?

TVMIA


In reply to Control break with Template::Toolkit by betacentauri

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.