score:26
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>
}}
Source: stackoverflow.com
Related Query
- Play 2.0 templating - Scala `match` and `val` do not compile in a view template
- Play and Scala: How to Declare val in view template
- Play 2 Scala - controller does not see model and view
- How to declare and access local variables in scala template in play framework?
- How to show images using Play framework and Scala in the view page
- Debug not working with play framework activator, scala and eclipse
- Mixing JavaScript and Scala in a Play template
- Scala pattern match and logical not
- Compile error in scala template while passing an arraylist: Not found value
- Scala Play passing variable to view not working
- Play Scala activator compile command shows value userid is not a member of play.api.data.Form[models.Changepas sword]
- Why is the each iteration parameter val and not var in for loop in scala
- Scala compile errors: "No implicit view available" and "diverging implicit expansion"
- Play framework Twirl template comparing javascript element and scala variable
- Scala match on Option[Object] not exhaustive with Some(o) and None in Akka receive function
- How to map multiple Futures and pass them as arguments to a view using Play with Scala
- Cast and instance of in scala view template in playFramework
- future.recover in Play for Scala does not compile
- Nested futures in Play for Scala does not compile
- Passing JSON String to Google Charts in Play Framework controller to Scala view is not recognized nor do the charts display
- Map variables not usable in Scala Play HTML template
- Action(parser.json) vs Action.async Error, and using concurrent.Execution.Implicits made could not initialize class controllers in Play Scala
- Return from function in body and not only in last line in REST API Scala and play
- Class not found in Scala template with Play Framework
- Jquery Not working in onchange function (Play scala view page and Ajax)
- Scala play JSON, lookup and match defined field holding null value
- How to get current day of the week and used it in scala template in Play framework
- Scala play coffee not compile javascript in public/javascript/
- How to prefill a dropdown using scala template and play framework
- Using Scala Play and Slick, how do I pass non-trivial relationships to the view
More Query from same tag
- Difficulty Training and Evaluating Neural Network Using DL4J, ND4J and Spark
- Calling Dataset static method does not work in Spark Shell
- Running a Spark Application in Intellij 14.1.3
- what is difference in creating instance with or without generic type in scala?
- Cannot build a scala program "sbt package" failed with Exception in thread "main" java.sql.SQLException: No suitable driver
- Create a copy of the folder within same remote server with SFTP
- How to set data for logistic regression in scala?
- Scala adding methods with complex types to final classes
- Scala: Play Framework 2 ignores httpOnly flag in application.conf
- Parsing JSON on Event Hub messages using spark streaming
- How to add meta tags when using the play framework?
- Tuple unpacking inside map
- Splitting strings on two different delimiters
- converting method to function?
- scala/java get json value using dot pattern
- Spark UDAF with ArrayType as bufferSchema performance issues
- How to update rows based on condition in spark-sql
- ClassNotFoundException when Loading Custom Class
- How to join 2 dataframes in Spark based on a wildcard/regex condition?
- Scala macros example not working on Scala 2.12.6
- java.lang.NoClassDefFoundError: org/apache/spark/sq/sources/v2/StreamingWriteSupportProvider trying to pull from kafka topic in scala
- Gatling: JsonPath extract multiple values
- How to invoke public static method for existing Java class instance from Scala?
- how to update all the values of a column in a dataFrame
- Is the best Scala convention to invoke collection.size or collection.length
- Scalatra Servlet init() during test (Jetty ServletTester)
- Scala timestamp/date zero argument constructor?
- Chisel Cannot reassign to read-only
- IllegalArgumentException when computing a PCA with Spark ML
- Graphx get vertex label from vertex id