How do you declare and initialize a variable to be used locally in a Play2 Scala template?
I have this:
@var title : String = \"Home\"
Actually, @c4k 's solution is working (and quite convenient) as long as you don't try to change the variable's value afterwards, isn't it?
You simply place this at the top of your template:
@yourVariable = {yourValue}
or, if it's a more complicated expression, you do this:
@yourVariable = @{yourExpression}
You can even work with things like lists like that:
@(listFromController: List[MyObject])
@filteredList = @{listFromController.filter(_.color == "red")}
@for(myObject <- filteredList){ ... }
For the given example, this would be
@title = {Home} //this should be at beginning of the template, right after passing in parameters
Using title @title
In the comments you said, that it gets typed to HTML type. However, that is only relevant if you try to overwrite @title
again, isn't it?