[Templates] loop.first, loop.last

Randal L. Schwartz merlyn@stonehenge.com
10 Jun 2006 10:47:49 -0700


>>>>> "Birgit" == Birgit Kellner <birgit.kellner@univie.ac.at> writes:

Birgit> Hi,
Birgit> I'm looping through an array of hashes with "foreach" and have problems using
Birgit> "loop.last":

Birgit> <p>
Birgit> <% foreach record in record_list %>
Birgit> <% record_lastname>, <% record.firstname %><% if not loop.last%>; <% end %>
Birgit> <% end %>:
Birgit> </p>

Birgit> However, the Template module throws an error:
Birgit> file error - parse error - pub_author.tmpl line 3: unexpected token (LAST) [%
Birgit> if not loop.last %].

Birgit> The same error is thrown by "unless loop.last".

Birgit> Can someone please explain this to me?

Unless you've done something other than just change your delimiters
away from [% %] to <% %>, the keywords are also (mostly) case-sensitive.
So you want things like:

<% FOREACH record IN record_list %>

etc.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!