score:1
you can simply wire this in through your controller.
def myview(): action[anycontent] = action { implicit req =>
val userid = req.session("user_id")
val user = finduser(userid)
results.ok(views.yourform(itemform, user))
}
then in your view:
<p class="username">${user.name}</p>
the finduser
method or whatever will allow you to search for a user
based on some kind of data within the request. req.session(key)
will return null
if the user is not logged in potentially so you may want an option[user]
instead.
the point is that you can pass through whatever variables to your form, and use @{variable.field}
syntax to display whatever you like. the twirl syntax allows you to do this, as well as for loops on collections to create a div for each element etc.
have a quick read through the twirl syntax, it should help you see all the examples of what it can do. to "get the data", it's generally preferable to put your logic in the controller, and pass it to your view.
Source: stackoverflow.com
Related Query
- How to pass in session variable to a form in play framework/scala to be stored in database
- Play framework Scala - how to pass text from a textInput in a form into a function
- How to pass optional parameter to scala template in play framework 2
- Play framework Scala - get session value in a form
- How to get environment variable in play scala Framework 2.5.0?
- How to pass additional form data to Scala Play
- how to convert ajax variable to scala variable in play scala framework
- How to pass Seq[(model, Seq[model2])] to Scala Play framework 2.5 view?
- How can I pass a play template scala variable as input to a scala function?
- In Play Framework 2, how do I pass in an external value for form validators to use?
- play 2.3.6, java 1.8 how to pass session to scala templates
- How to save Scala List object in session for Scala Play framework
- How to use IntelliJ with Play Framework and Scala
- How do you change the Play 2.1! Framework session cookie name
- How to test a Scala Play Framework websocket?
- How to create a global variable with Play Framework 2.0
- How do I get Intellij IDEA 12.0 to work with Play Framework 2.1.0 app and Scala 2.10.0?
- How to show images using Play framework and Scala in the view page
- Play Framework 2 scala specs2 mockito, how do I write a mocking unit test
- How do I unit test a controller in play framework 2 scala
- Better ways to implement more secure Play Scala framework session via cookie
- How do you use play framework as a library, in a scala project
- How to call a template which accepts variable number of args in Play Framework 2
- Inline variable in the Play framework 2.x Scala template
- Play 2: How to parse a dynamic list of form inputs in Scala controller?
- How do I unit test akka actors in Play Framework 2.2.0 Scala (spec2, Mockito)
- How do I ignore ssl validation in play framework scala ws calls
- How to list out all the files in the public/images directory in a Play Framework 2 Scala application?
- How to pass a session variable from one object to another in Gatling?
- Using scala and java in play framework 2.1 : Session usage
More Query from same tag
- How to get the sum of two elements from the Spark RDD Iiterable
- Implementing @routes.Assets.versioned("") in java class
- Manipulating Vectors and Lists in RDDs
- How to disable play 2.6 CSRFFilter
- Why the compiler does not recognize the properties?
- How to properly use fold left in a scala function
- How to transform a "pimp" method to accept a tuple?
- CIRCE: How to decode a json model with disjunction in a field type
- Scala / Java Sandbox for untrusted code
- Multiple message sends in Akka-Scala-Camel-TCP Sockets going to dead letters
- scala: recursive function composition
- How can I set javaOptions in a custom sbt command
- What does the arrow in an import statement do?
- Apache Spark and Remote Method Invocation
- Will simplify inserts into tables with auto-generated primary keys?
- Change forEachRDD
- getOrElse method not being found in Scala Spark
- scala map / type instantiation
- What does scala reflection API Type.dealias do?
- Type inference fails on Set made with .toSet?
- Is there a way to get the direct parents of a ClassSymbol in macro context?
- Hazelcast server with scala client issue
- Akka, Camel and HTTP polling
- explicitly close db connection in slick
- How to use fully formed SQL with spark structured streaming
- Scala 3 -Ysafe-init and -Yexplicit-nulls do not report unsafe null inits in classes?
- sbt-native-package Debian versus JDKPackager
- to[List] on a generic HList after Partition
- Accompanying object for trait in Scala
- Spark Scala Seq append. Should I broadcast the variable?