Search code examples
htmlscalatemplatesplayframeworkplayframework-2.0

Declare variable in a Play2 scala template


How do you declare and initialize a variable to be used locally in a Play2 Scala template?

I have this:

@var title : String = "Home"

declared at the top of the template, but it gives me this error:

illegal start of simple expression """),_display_(Seq[Any](/*3.2*/var)),format.raw/*3.5*/(""" title : String = "Home"

Solution

  • @defining("foo") { title=>
      <div>@title</div>
      ...
    }
    

    basically, you have to wrap the block in which you are going to use it