Javier Gutierrez
Javier Gutierrez

Reputation: 559

Scala val unrecognized in playframework

please, i trying to use a val parameter in a for template but it is unrecognized

@{val slide=0 }
            @for((parent, index) <- grandparents.zipWithIndex){
                @for((son, jndex )<- parent.zipWithIndex){
                    @{slide++}
                }
            }

Upvotes: 1

Views: 124

Answers (2)

avik
avik

Reputation: 2708

As an extension to Samy's answer, here's what your @defining block might look like:

@defining(grandparents.foldLeft(0)((i,parent) => i + parent.size) {slide =>
  // Insert any markup here that depends on the value of slide
}

Upvotes: 0

Samy Dindane
Samy Dindane

Reputation: 18746

You can't declare and use a Scala val in the templates.
You need to declare a reusable value using the defining helper, as explained in the template engine section of the documentation.

(plus, you can't change the value of a... val; you must use the var keyword)

Upvotes: 3

Related Questions