Reputation: 1049
I am trying to iterate in a playframework view, but without success for now. I have the following structure:
@if(list != null) {
for(a <- 0 to list.size()/5)
{
// some html, where I want to get the value of a
for(b <- a*5 to a*5+5) // here I want to use the a value again
{
some html
}
}
So my question is how to get the current index of the loop so that I will be able to use it.
Upvotes: 0
Views: 3467
Reputation: 1722
You should combine it in one for loop:
@if(list != null) {
@for{a <- 0 to list.size()/5
b <- a*5 to a*5+5}
yield html
}
}
And use option instead of null
checking.
Also you can use map
function to transform your list. See details in Play documentation - http://www.playframework.com/documentation/2.0/ScalaTemplates
Upvotes: 5