Reputation: 33
I'm using the play framework template engine based on scala. The controller are written in Java.
Is there a way to define a inline writable variable?
I just found this at the documentation:
@defining(user.getFirstName() + " " + user.getLastName()) {
<div>Hello @fullName</div>
}
But this only create a readonly variable.
Edit: I am using a loop in my html page:
@for(variable <- variables) {
This kind of a loop dosen't give me a index variable. I need this index to give different outputs for the first loop and all others. Hope this is clear?
So I just thought I could create a index variable outside the loop and increment it on each loop.
Has anyone an idea? Thanks
Upvotes: 3
Views: 1802
Reputation: 55798
Try:
@for(for(i <- 0 to list.size-1) {
@list(i)
}
or simply:
@for(i <- list.indices) {
@list(i)
}
Upvotes: 6
Reputation: 4216
I think zipWithIndex is what you need:
@variables.zipWithIndex.map { case (variable,index) => <h1>@variable</h1>}
Upvotes: 4