question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Play 2.3.8] If condition bring line feed in scala template

See original GitHub issue

Hi 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:open
  • Created 8 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
steinybotcommented, Aug 23, 2017

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

@(givenName: String)(content: Txt)
Hi @givenName,

@content

Thanks

newAccountEmail.scala.txt

@(givenName: String, admin: Boolean, url: String)
@baseEmail(givenName) {
@if(admin) {
An administrator account has been created for you.

Once you have activated your account, you can create accounts for other users in your organization.
} else {
An account has been created for you.
}

Use the link below to set the a password and activate your account.

Set password: @url
}

The current workaround:

newAccountEmail.scala.txt

@(givenName: String, admin: Boolean, url: String)
@baseEmail(givenName) {@if(admin) {An administrator account has been created for you.

Once you have activated your account, you can create accounts for other users in your organization.} else {An account has been created for you.}

Use the link below to set the a password and activate your account.

Set password: @url}

If braces could go on the following line it would be a little bit better:

newAccountEmail.scala.txt

@(givenName: String, admin: Boolean, url: String)
@baseEmail(givenName)
{@if(admin)
{An administrator account has been created for you.

Once you have activated your account, you can create accounts for other users in your organization.}
else
{An account has been created for you.}

Use the link below to set the a password and activate your account.

Set password: @url}

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)

0reactions
steinybotcommented, Aug 23, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found