Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I call session in template/view on Play Framework

I'm new at using Play Framework 2.0 (I am using Scala) and have a question about sessions.

I come from a Ruby on Rails background, so I tend to think of everything that I learn in Play Framework with respect to Ruby on Rails.

With that in mind, is there any way for me to call stuff stored in the Session while I am in the view?

If I have "hello" -> "world" stored in the Session, I want to be able to do something like @session.get("hello") and be able to use "world" in the view. Is this possible?

The other option I see is to store the value in a variable in the controller, and pass that along to the view by doing something like OK( var ), but that way seems kind of clunky especially if I start using more variables.

Thanks!

like image 320
wynnch Avatar asked Jun 04 '12 21:06

wynnch


1 Answers

Sessions in Play store in cookies and are really just for cross-request data. If that is what you want then you can use @session.get("hello") but what you might actually be after is a way to pass stuff from controllers to templates without having to specify them as parameters. In that case, see the very detailed answer to that question here: https://stackoverflow.com/a/9632085/77409

like image 87
James Ward Avatar answered Oct 21 '22 09:10

James Ward