I’d like a Scala condition inside the “class” HTML attribute to be parsed, but the Scala Template isn’t playing ball:
@priceTag(amount: Currency) = @{
<div class='priceTag {if(amount.toDouble == 0.0d) "FREE"}'>
{if(amount.toDouble > 0.0d) {amount.format("¤#")} else {"FREE"}}
</div>
}
Yields:
<div class="priceTag {if(amount.toDouble == 0.0d) "FREE"}">
£1
</div>
And I’d like it to yield:
<div class="priceTag">
£1
</div>
Suggestions gratefully appreciated
Your code has several errors. They just hide each other. 🙂
Let’s go through them:
The
@{ ... }construct means that everything inside the curly brackets is a block of Scala code. This doesn’t rause an error, because your block,is actually valid Scala code (because of Scala’s XML literals). It’s just that Scala recognizes
priceTag {if(amount.toDouble == 0.0d) "FREE"}as the class name of yourdiv.What you probably wanted to do is this:
Notice the
@signs before the twoifblocks. I have also removed the curly brackets aroundamount.format("¤#")and"FREE". You can keep them of course, if you want, but they’re not required.