Current index in <apex:repeat> loop

Posted on 21-02-2013 10:13 by graham
This tutorial shows you how to use an index of the current iteration in the apex:repeat tag.

Unfortunately, the apex:repeat loop itself does not have the attribute index similar to that you can use in JSTL's c:forEach. This is why our solution uses a workaround with the apex:variable tag.

<apex:variable value="{!0}" var="index" />

<apex:repeat value="{!items}" var="item">
The current index is {!index}

<!-- increment index -->
<apex:variable value="{!index + 1}" var="index" />


Add comment

Has this tutorial been helpful to you? Or do you see anything wrong? We appreciate your opinion!
Your comment:
Show formatting hints
HTML is disallowed, but in your text you can use the following markup
  • [code][/code] for a block of code
  • [tt][/tt] for inline code
  • [link]link href|link anchor[/link] for links
  • [b][/b] for bold text
+ Ask a question
If you have a technical question related to programming and computers, ask it here. Other users will help you solve it!
Unanswered questions
Share your knowledge by helping others solve their problems