How to declare and access local variables in a scala template in a playback platform?

I have code in a scala template, for example:

@for(col <- List.range(0,12)) { <td> @if(col % 2 == 0) { @{ val letter = someMap(col) } <div class="z@(letter)@(letter)s"></div> } </td> } 

But I get a compilation error: the letter of the value was not found. How can I declare variables and be able to access later in the markup as above?

+8
scala playframework
source share
1 answer

In fact, I never saw @if or tried PlayFramework. But if that is the case, then I think that when you are actually trying to request a letter, it is already out of scope. What happens if you adjust the brackets as follows?

 @for(col <- List.range(0,12)) { <td> @if(col % 2 == 0) { @{val letter = someMap(col) <div class="z@(letter)@(letter)s"></div> } } </td> } 
+7
source share

All Articles