Gossamer Forum
Home : Products : Gossamer Forum : Discussion :

Loop Iteration

Quote Reply
Loop Iteration
When a template is parsed is it possible to extract a loop count, something like...

Code:
<%loop whatever%>
<%if loop_iteration == 1%>
<p>this is the first pass
<%else%>
<p>this is not
<%endif%>
<%endloop%>
Quote Reply
Re: [kooSH] Loop Iteration In reply to
Hi,

Yes, definately. The following tags become available inside a loop:

<%row_num%> - a counter for what row is being looped, starts at 1.
<%first%> - boolean that is true if this is the first row, false otherwise.
<%last%> - boolean that is true if this is the last row, false otherwise.
<%inner%> - boolean that is true if this is not first and not last.
<%even%> - boolean is true if row_num is even.
<%odd%> - boolean is true if row_num is odd.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Loop Iteration In reply to
Thanks Alex,

Is there a definitive list of all such variables?


moog
-- I've spent most of my money on beer and women... the rest I just wasted.
Quote Reply
Re: [Alex] Loop Iteration In reply to
That's very impressive, Alex!

I was just damning Perl myself today that there wasn't a built in way of knowing that you're at the last itteration of a loop. But I was told that it might actually be in the works for Perl 6 :-)

- wil
Quote Reply
Re: [kooSH] Loop Iteration In reply to
Hi,

Yes, it's all in the GT module documentation. In your admin, click on Help, Table of Contents, and then GT Module Documentation. Scroll down on the left and click on Template to see all the things you can do in the template parser.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Loop Iteration In reply to
Fantastic!!!

Cheers,
Trav.


moog
-- I've spent most of my money on beer and women... the rest I just wasted.