How do I declare and increment a variable in play2? (in .scala.html templates)
Pseudo code:
@counter
@for(l <- list){
<span class="data-@counter">
</span>
@(counter += 1)
}
Do you really need counter and incrementing? You can do this:
@for((l, index) <- list.zipWithIndex){
<span class="data-@index">@l</span>
}
Method zipWithIndex
creates list of tuples.
to declare at template
@import java.math.BigInteger; var i=1
for increment in template
@(i+=1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With