I'm just starting with playFramework with the intention on speeding up a web application development taking advantage of my background in Java. As Scala seems to be the most commmon option for the views in play, I decided to use it despite being new to it (and not intending to deepen into it, at least for now).
Well, I just figured out that "type" is a reserved word in scala, and though I've seen other Q&As such as Is there a way to use "type" word as a variable name in Scala? and How to use Java package com.example...object in Scala saying that I just needed to add to enclose type with ` `
However, when I use the template code below:
<dl>
@for(alarm <- alarms){
<dt>@alarm.id</dt>
<dd>@alarm.`type`</dd>@* type is a scala keyword, so I had to escape it *@
<dd>@form(routes.Application.deleteAlarm(alarm.id)) { <input type="submit" value="Delete"> }</dd>
}
</dl>
it outputs:
models.Alarm@1.
type
instead of the value of type.
How can I escape the keyword in this case?
Seems you are looking for this:
@{alarm.`type`}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With