I am working on a project using PlayFramework 2.0. After reading a bit of scala I would like to embed some dynamic code in the View template. So, I did the following:
@{
def getMystring(sequence:Int) = {
if(patternForm != null &&
patternForm.get().windowTreatments != null &&
patternForm.get().windowTreatments.size() >= sequence + 1)
sequence+""
else
""
}
}
<input type = "text" value = @getMystring(1)></input>
...
I was quite sure it was going to work but instead I got a "not found: value getMyString Error occurred" . Did I do something obviously wrong?
The problem being that play defines a very narrow scope and can't recognize defs outside its current curly brackets.
You can change the position of the last curly bracket for your def to include the input tag and then it should work.
Or you can do what opensas suggested.
try starting it like a template, like this
have a look at https://github.com/playframework/Play20/blob/master/samples/scala/computer-database/app/views/list.scala.html