Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play Framework 2.0 template engine define writabel variables

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

like image 671
Jurek Avatar asked Nov 30 '25 09:11

Jurek


1 Answers

Try:

@for(for(i <- 0 to list.size-1) {
   @list(i)
}

or simply:

@for(i <- list.indices) {
    @list(i)
}

(tip from google group)

like image 166
biesior Avatar answered Dec 02 '25 04:12

biesior



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!