I need to print some raw HTML in a Scala template using the latest Play Framework 2.1.1 Messages, variables simple for loops, etc. everything is working fine. But what if I need to do some logic and print the raw HTML in a template?
@{
val courts = venue.getCourts()
val totalWidth : Int = 920
.. some other initialization variables/values
var output : String = ""
for(court <- courts) {
output += "<p>SomeComplexString</p>"
}
output
}
In this case, the function @{}returns output, but this HTML code is escaped, and also it is not so practical (combining everything into one variable outputbefore returning).
If I put something like
for(court <- courts) {
println("<p>SomeComplexString</p>")
}
it does not work (I do not get compilation errors, but there is nothing on the output).
I could do
@for(court <- courts) {
<p>SomeComplexString</p>
}
but then it courtswill be unavailable (let's say that I cannot define it courtsas a template variable at the beginning).
What's the solution?