* Viljo Marrandi ([EMAIL PROTECTED]) [011031 06:32]: > I know there must be a simple solution for this problem, but i didn't > find it in docs. > > How can i print out inside FOREACH loop (or WHILE or WHATEVER) how many > loops it has already done? Is there some kinda counter which counts it? > Basically I'd like to get something like this: > > [% FOREACH element = array %] > [% loop.number %]. [% element.value %] > [% END %] > > output: > > 1. value1 > 2. value2 > 3. value3 > ...... > > I could increment my own counter, but it seems too hard.
For FOREACH, TT maintains an implicit 'loop' variable, so you can do: [% FOREACH element = array %] [% loop.count %]. [% element.value %] [% ' - 30 - 'IF loop.last %] [% END %] See 'perldoc Template::Manual::Directives' for the real scoop. Chris -- Chris Winters ([EMAIL PROTECTED]) Building enterprise-capable snack solutions since 1988.
