score:26

Accepted answer

Using match expressions in templates

You need to enclose in braces (“{” and “}”) the HTML content of your templates:

@for(line <- content.toString.lines) {
  @line match {
    case "" => { }
    case _ => { <li>@Html(line)</li> }
  }
}

In your specific case, the following code would read better IMHO:

@content.toString.lines.collect {
  case line if !line.isEmpty => { <li>@Html(line)</li> }
}

Defining values

You can define values using the defining[T](value: T)(usage: T => Html) helper:

@defining(1 + 2 * 3) { value =>
  <div>@value</div>
}

score:0

Another frequent cause of this error is to have the starting brace on a separate line:

@x match {
case y => 
  { //offending brace, put it back on the same line as case
  } //This can go anywhere
}

score:1

following seems to work for me

@content.toString.lines.map{ line => 
    line match {
      case "" =>  @Html("")
     case _ => <li>@Html(line)</li> 
}  

hard on eyes, but you can look at target/scala-2.9.1/src_managed/main/views/html/index.template.scala in the play project directory to see what its putting in string literals.

As for val assignment, I don't know, but @defining may help

score:4

I found that add a {} outside to enclose entire code would work

@{content.toString.lines.map{ line => 
  line match {
    case "" =>  @Html("")
    case _ => <li>@Html(line)</li> 
}}  

Related Query

More Query from same tag