Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escaping scala reseverd word "type" in scala templete in play framework

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?

like image 961
Thomas Avatar asked Mar 13 '14 12:03

Thomas


1 Answers

Seems you are looking for this:

@{alarm.`type`}
like image 65
serejja Avatar answered Nov 08 '22 06:11

serejja