scalatra
scalatra copied to clipboard
Add reverse route support for Twirl
This is a port of reverse routing support for Scalate in the scalatra-scalate module: https://github.com/scalatra/scalatra/blob/2.7.x/scalate/src/main/scala/org/scalatra/scalate/ScalateUrlGeneratorSupport.scala
First, controller must extend TwirlReverseRouteSupport.
class MyController extends ScalatraServlet with TwirlReverseRouteSupport {
val login = get("/login"){
...
}
val article = get("/article/:id"){
...
}
}
Then you can render URL of specified routes (specify by bound field names) in Twirl templates as follows:
@import org.scalatra.twirl.url._
@()(implicit request: javax.servlet.http.HttpServletRequest)
...
<!-- Without parameter -->
<a href="@url("login")">Login</a>
<!-- With parameter -->
<a href="@url("article", "id" -> "123")">Article</a>
...
@takezoe
I think that it is necessary to merge this PR for the release of Scalatara 2.7. Are there any blocking factors at present?
There is no blocker.
Why I haven't merged this pull request yet is that I'm not sure if this feature is actually necessary because I don't use the reverse routing even with Scalate.
Also I'm wondering if there is a better way to support it than url helper.