Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reverse route support for Twirl #768

Open
wants to merge 1 commit into
base: 2.7.x
Choose a base branch
from

Conversation

takezoe
Copy link
Member

@takezoe takezoe commented Nov 26, 2017

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 takezoe added this to the 2.7.0 milestone Nov 26, 2017
@takezoe takezoe mentioned this pull request Nov 26, 2017
24 tasks
@magnolia-k
Copy link
Contributor

@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?

@takezoe
Copy link
Member Author

takezoe commented May 6, 2019

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.

@takezoe takezoe modified the milestones: 2.7.0, 2.7.1 Feb 29, 2020
@takezoe takezoe modified the milestones: 2.7.1, 2.7.2 Dec 19, 2020
@takezoe takezoe removed this from the 2.7.2 milestone Jul 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants