Knowledge base/Tips & Tricks

Row counter

Technical Support
posted this on February 10, 2009 10:19

In every <%foreach element IN ...> cycle a counter is available through variable %-element_index-%.

<%FOREACH product IN results>
This is item n.%-product_index-%
</%FOREACH>

You can conveniently use this feature to alternate effects or insert row delimiters:

<%FOREACH product IN results>
   <%SHOWIF (%-product_index-% % 2)> This is an odd item </%SHOWIF>
   <%SHOWIF !(%-product_index-% % 2)> This is an even item </%SHOWIF>
</%FOREACH>

Counter starts from 0.

 
Topic is closed for comments