Declare variable in a Play2 scala template

travega picture travega · Aug 20, 2012 · Viewed 41.2k times · Source

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"

Answer

virtualeyes picture virtualeyes · Aug 20, 2012
@defining("foo") { title=>
  <div>@title</div>
  ...
}

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