http://www.perlmonks.org?node_id=1022189


in reply to Template Toolkit foreach loop

Without a dump of the data which is being sent to template toolkit or a clearer description of how you want them grouped it is difficult to say.

Assuming you have an array of hashes named files, with date as a key in each hash, containing the date as formatted in your question. You could do something like this.

[% FOREACH file=files %] [% IF ( matches = file.date.match('dd/mm/(\d+)') ) %] <a href='#'>[% matches.0 %]</a> [% END %] [% END %]

Replies are listed 'Best First'.
Re^2: Template Toolkit foreach loop
by sundialsvc4 (Abbot) on Mar 07, 2013 at 14:34 UTC

    I tend to try to put logic concerns in the application, and presentation concerns in the template.   Usually, one subroutine is called to build the page.   It assembles information in its local variables, sometimes also defines a “closure” (a code-ref) that the template will use to withdraw the information that it needs, then invokes the template.   The information it needs is prepared in advance.   The template drives how it looks, and if Marketing wants to completely re-design that, the program won’t break.