Ack, in my examples below, I had meant to use replace LOOP with FOREACH.

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Stephen Howard
Sent: Monday, November 05, 2001 12:06 PM
To: [EMAIL PROTECTED]
Subject: RE: [Templates] FOREACH/ELSE


Well, Andy's inclusion of BEFORE and AFTER save you an IF block before and after your 
loop if you need to do setup/teardown stuff
for the loop.  And that was really the thing that seemed to be missing from Brett's 
original suggestion.  I do like Andy's choice of
syntax as well, though I'm wondering if we couldn't just make this new kind of loop an 
extension of FOREACH, so that FOREACH could
be used as:

-------------------------
simple case

[% FOREACH item = list %]
foo
[% END %]

-------------------------
complex case

   [% LOOP item = list %]
      <tr><td>[% item %]</td></tr>
   [% BEFORE %]
      <table>
   [% AFTER %]
      </table>
   [% EMPTY %]
      There are no items in the list.
   [% END %]

-------------------------
a medium-case

   [% LOOP item = list %]
      <p>[% item %]</p>
   [% BEFORE %]
      Here are your search results:
   [% END %]


_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://www.template-toolkit.org/mailman/listinfo/templates



Reply via email to