playframework-2.0scala-template

Initailzing variable in scala template


I have a simple code in scala template for Play

@( val i = 0){
.......
....

i => i+1; // incremental 
}

But the above code is not working any idea how to fix this ?


Solution

  • You can fetch the index of the iteration in Scala for loop, just zipWithIndex your collection:

    @for((day, index) <- model.days.zipWithIndex) {
        <li>Day @index is @day</li>
    }
    

    like described in other question