>>>>> "Ronald" == Ronald J Kimball <[email protected]> writes:

Ronald> You should be outputing only the current address each time through the
Ronald> loop.  Here's an example:

Ronald> [%- mylist = [ 'one' ] %]
Ronald> [%- mylist = [ 'one', 'two' ] %]
Ronald> [%- mylist = [ 'one', 'two', 'three' ] %]
Ronald> [%- FOREACH item IN mylist %]
Ronald>   [%- IF loop.max() == 0 -%]
Ronald>     [%- item %].
Ronald>   [%- ELSIF loop.last() -%]
Ronald>     [%- IF loop.max() > 1 %]or [% END %][% item %].
Ronald>   [%- ELSE %][% item %], [% END %]
Ronald> [%- END %]

Ronald> I put one of the [% END %]s at the end of the line to preserve the 
trailing
Ronald> space character in the output.  Adjust the style to your liking.

I find this a little clearer:

$ tpage
[%
BLOCK listem;
    FOR item IN items;
      item;
      ", " IF loop.count < loop.max;
      " or " IF loop.count == loop.max;
    END; # FOR
END; # BLOCK

FOR try = [0..5];
  try; ": <";
  INCLUDE listem items=[1..try];
  ">\n";
END; # try
%]
^D
0: <>
1: <1>
2: <1 or 2>
3: <1, 2 or 3>
4: <1, 2, 3 or 4>
5: <1, 2, 3, 4 or 5>
$


-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[email protected]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.posterous.com/ for Smalltalk discussion

_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to