The playframework 2.0 function defines in the view template

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 sure that this would work, but instead I got the message "not found: value getMyString Error". Did I do something obviously wrong?

+4
scala playframework
source share
2 answers

The problem is that the game defines a very narrow scope and cannot recognize defs outside its current braces.

You can reposition the last curly bracket for your def to include an input tag, and then it should work.

Or you can do what was suggested.

 @getMystring(sequence:Int) = { [...] 
+3
source share

try running it as a template, for example

 @getMystring(sequence:Int) = { [...] 

take a look https://github.com/playframework/Play20/blob/master/samples/scala/computer-database/app/views/list.scala.html

+5
source share

All Articles