Play Framework: How do I get querystring value inside html template file

I am working on Play Framework 2.0 for Java and I have a querystring url like http://localhost:9000/project/detail?id=1, when this url hits It will call a HTML template file eg.detail.scala.html. So I want to check is there querystring exist in url in my HTML file.

ex:

@if(existsQueryString) 
         @showPerticularProductDetail
else
         @showAllProductList

Please help me or give any suggestion for this. I dont want to pass some variable or any flag from controller to view for checking the condition. I just want to check is querystring there in url inside my HTML.

Answers


You can access the request either directly if you're in a Java project, or via an implicit parameter if you are in a Scala project.

In a Java project, you can use it directly to check the queryString :

@if(request.queryString.containsKey("myKey")){
     @showPerticularProductDetail
else
     @showAllProductList

If you're in a Scala project, you need to add the request as an implicit parameter of your view :

@(title: String)(implicit request: play.api.mvc.Request)

And your controller should also declare this implicit parameter :

def detail = Action { implicit request =>
    ...
    myTemplate.render()
}

Need Your Help

Not able to download the newly added files from TFS 2013

visual-studio-2012 tfs azure-devops tfs2013

We are using TFS 2013 (internal server) and use VS 2012 for develop.

Django rest framework ignores has_object_permission

python django django-rest-framework

I'm trying to limit the access to objects for users. Only creaters should modify objects. For that purpose like they say in tutorial I've written