Kory
Kory

Reputation: 477

How to use flash and session in a view in Play Framework? [Scala]

I need to pass both a flash value and a session value into one view in Play Framework. Is this possible?

Upvotes: 1

Views: 732

Answers (2)

Ardavan Khalij
Ardavan Khalij

Reputation: 1

@()(implicit flash : Flash, request: RequestHeader)

And then you can use it like this:

@if(request.session.get("example").toList(0) == example2){
<a href="#example>"><h5>example</h5></a>
}

Upvotes: 0

Daniel Olszewski
Daniel Olszewski

Reputation: 14401

Both the session and the flash objects are accessible from the request. Simply pass request from a controller to a view. Usually it's done by an implicit parameter:

@()(implicit request: RequestHeader)

@request.session.get("yourSessionKey")
@request.flash.get("yourFlashKey")

Upvotes: 3

Related Questions