Play framework: is there a way to avoid the weird syntax of the form helper?

I am trying to create a form with Play Framework 2, the usual syntax is :

@helper.form(action = routes.Application.submit, 'id -> "myForm") {   
}

Note that the single quote is before opening and never closes.

Is there any other syntax that I can use to do the same?

+4
source share
3 answers

'id- Symbol.

You can use the syntax Symbol("sym")if you do not like this, but it is not standard.

scala> 'symbol == Symbol("symbol")
res0: Boolean = true
+4
source

. scala, (, java, ).

//SymbolImplicits.scala

package example.libs

object SymbolImplicits {
    implicit def string2Symbol[A](s: (String, A)): (Symbol, A) = (Symbol(s._1), s._2)
}

, , @import example.libs.SymbolImplicits._, :

@helper.form(action = routes.Application.submit, "id" -> "myForm") {   
}

"id" -> "myForm" 'id -> "myForm".

, build.sbt ( Build.scala ):

TwirlKeys.templateImports += "example.libs.SymbolImplicits._"
+3

, Scala Symbol, , , , , , .

+1

All Articles