Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play2 - Template -> incrementing

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)
}
like image 846
Maik Klein Avatar asked Nov 28 '22 16:11

Maik Klein


2 Answers

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.

like image 144
Infinity Avatar answered Dec 05 '22 08:12

Infinity


to declare at template

@import java.math.BigInteger; var i=1

for increment in template

@(i+=1)
like image 33
Govind Singh Avatar answered Dec 05 '22 10:12

Govind Singh