I am using Play Framework 2.5, dealing with scala.html and Twirl templates. Can someone please help me understand how to set the "key" on my span to be my "val id"?
I cannot seem to get this to work within html element attributes.I am not sure what syntax to use get my val id written to my span key.
Thanks for any help.
@{
val rank = player.rank
val id = player.id
if(rank == "Great") {
<span key="{id}">{rank}</span>
} else if(rank == "Good") {
<span key="{id}">{rank}</span>
}
}
You can't add html inside a @{ }
block. What you want is probably something like this:
@if(player.rank == "Great") {
<span key="@player.id">@player.rank</span>
} else if(player.rank == "Good") {
<span key="@player.id">@player.rank</span>
}
Declaring variables in these templates is not as easy as it seems. Check the documentation for some examples.