I noticed a pattern recently whereby we often call a count prior to iterating over the resultset: [% IF things.count %] <table> . . . [% FOREACH thing IN things %] <td>[% thing.whatever %]</td> [% END %] </table> [% END %] This introduces a count(*) DB call. We could instead use the first iteration of the iterator to setup the boilerplate and reduce our DB hits. [% FOREACH thing IN things %] [% IF thing.first %] <table> [% END %] <td>[% thing.whatever %]</td> [% IF thing.last %] </table> [% END %] [% END %]
Doh.. it's wouldn'y be 'thing.first' and 'thing.last'.. it would be the special variables.. 'loop.first' and 'loop.last' in the above example.
Sounds reasonable to me
Sometimes we need to know if there is are least 1 row, to display a title for instance, or actions (check/uncheck all) at the top of the table. We will then end up with 2 patterns. Not a big deal, but worst noting it. Maybe better to have a TT var defined at the top of the template then reused all along?