Hi So I have a while loop:
@for(i <- 0 until consoles.size) {
... Do something
... Add records to a column
}
But what I would like to add a variable and depending on what is going on add it to a different group. For example:
@var column = 0;
@for(i <- 0 until consoles.size) {
@if(consoles[i].groupname != consoles[i - 1].groupname) {
column = column + 1;
}
... Do something
... Add records to a column
}
Is this possible. The only thing I have found is by passing in a variable and using that but I would prefer not to do that, although it will only be an int so not sending alot more information to the client I would prefer if I could just declare in the scala template?
Any help would be appreciated.
In play templates you can't define
var
. Furthermore, in Scala you are encouraged to use immutable objects rather than mutable ones.You have two alternatives to do what you want:
val
sIn addition to @Maxime's answer, you can create new
val
s in your template usingdefining
From play 2 documentation :
In your case there are better solutions. Since templates are in scala, you can use some great methods from Collections' API, such as groupBy :
Scala templates doesn't require Scala skills, but you need at least to understand the lists API, it's a true life saver !