Using Play 2 I am realising a simple REST API, the output is plain text. My template looks like this:
@(items: Map[String,String]) @for((key, value) <- items) { @value @key }
In the controller:
return ok(views.html.bla.render(itemsMap)).as("text/plain");
This gives the following output:
(empty line) (empty line) value key (empty line) value key
I want to get rid of the first 2 empty lines – is that possible?
Putting the for in the first line removes one of the empty lines at the top, however one still remains and for in the first line makes the template hard to read ): Thanks for any hint!
Answer
First off, if you use plain text, you should use txt templates (bla.scala.txt
). They also automatically set text/plain; charset=utf-8
content type.
To trim the content, you can return the rendered content directly:
return ok(views.txt.bla.render(itemsMap).body().trim());
In case you want to render HTML content you’d need to change this manually:
return ok(views.html.ble.render().body().trim()).as("text/html; charset=utf-8");