playframework - Rendering newline charactors from variable in Twirl -


i have toy play framework project. , java code like:

    string r = "apple\nbanana";     return ok(index.render(r)); 

and index.scala.html like

@(r: string)  <table border="1" style="width:98%"> <tbody>   <tr>     <td>@r</td>   </tr> </tbody> </table> 

the problem that, in displayed html, newline character gone. want 2 lines in html 1 line.

i tried changing line in java like:

 string r = "apple<br>banana"; 

but html still shows 1 line instead of 2 lines, shows

"apple<br>banana" 

so how can 2 lines (making newline character work) in twirl?

be default, twirl escapes html tags dynamic content. if want render tags variable can use @html(). in case this:

@(r: string)  <table border="1" style="width:98%"> <tbody>   <tr>     <td>@html(r)</td>   </tr> </tbody> </table> 

obviously new line character doesn't work because browsers ignore white spaces while rendering html output.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -