简体   繁体   中英

play 2.3.6, java 1.8 how to pass session to scala templates

I know there are a lot of SO links with this in discussion but either they are related to old framework version or they don't work for me,

what I want to do is pass session to scala templates without having to pass them explicitly form controllers, I didn't find examples(working) of implicit parameters in play 2.3.x version, my view is rendered as ok(welcome.render(msg)) and in my template I'm doing @(notice: String)(implicit session: play.api.mvc.Session) but it gives me method render in class welcome cannot be applied to given types; error, I also tried with

@(notice: String)(implicit request: play.api.mvc.Request[Any]) @(notice: String)(implicit request: RequestHeader)

but none seem to work, I know I can pass required session values from the controller but I'm trying to send some user data that'd be required in the navbar which would be required in each view so I don't want to send it from the controllers.

Any help would be greatly appreciated

Play Session might be retrieved from scala templates by session helper, just as the statement below. Altough I'm using play 2.2.1, it may work for you as well. Btw, i have never needed implicit parameter in order to reach it.

@session.get("keyvalue") 

I may have misunderstood your question, but if you want to get session values from view that's the standard way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM