Question

When I write this code bellow in my login.scala.html, only the words 'foo' are showed, in other words, 'bar' is never showed.

<body>
    @{
        <span>bar</span>
        if(true)
        {
            <span>foo</span>
        }
    }

    @{
        <span>bar</span>
        for(i <- numbers)
        {
            <span>bar</span>
            <span>i.toString()</span>
        }
    }
</body>

Someone knows why?

Was it helpful?

Solution

As you used the block statement, it returning the last expression.

For example (try it in REPL):

val a: Int = 10 
val b: Int = 20
{
a
b
}

Output:

res0: Int = 20
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top