[Play 2.3.8] If condition bring line feed in scala template
See original GitHub issueHi all,
I am facing issue with if conditions in scala template. In the following circumstance, the html will have white spaces and line breaks in between the two divs.
<div>
content in previous div.
</div>
@if(condition) {
<div>
content in next div
</div>
}
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Scala Templates - 2.8.x - Play Framework
Syntax: the magic '@' character. The Scala template uses @ as the single special character. Every time this character is encountered, it indicates...
Read more >if statement in scala template play framework - Stack Overflow
hey guys am trying to send a value for user if he is logged in and in not i execute an if statement...
Read more >Ammonite
Ammonite provides a set of magic imports that let you load additional code into a REPL session: these are imports which start with...
Read more >sbt Reference Manual — Combined Pages
If you have any trouble running sbt, see Command line reference on JVM options. ... directory the following nested directories: src/main/scala/example .
Read more >PlayFramework.apply(0) = "Templates, Routes and AJAX"
In addition, you will need to get a copy of the Play Framework ... may not directly match the example here, so if...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Another solution that may work is to allow any whitespace to go between the keyword and the brace.
Here is an example of how I want to use Twirl:
baseEmail.scala.txt
newAccountEmail.scala.txt
The current workaround:
newAccountEmail.scala.txt
If braces could go on the following line it would be a little bit better:
newAccountEmail.scala.txt
Ideal solution would be to have some kind of directive that allows the whitespace stripping from lines that only contain tags. At least this would be backwards compatible. Something like:
@setting(settings.stripTagLines, true)
This makes Twirl impractical for plain text templating, say for example when you have both HTML and plain text emails.
I quite like having the template separate from my code.
I think the approach that Freemarker takes with whitespace stripping and an additional
compress
directive is pretty good and solves the simple cases.