开发者

How do I make session/cache variables available to my main.html template?

开发者 https://www.devze.com 2023-03-30 10:26 出处:网络
I\'m using Play Framework and setting a cache value as such: String sessionId = Scope.Session.current().getId();

I'm using Play Framework and setting a cache value as such:

String sessionId = Scope.Session.current().getId();
Cache.set(sessio开发者_如何学GonId + "_user", "Doser");

and I want to ouput the value in my main.html without adding the value to every single controller in my application.

How do I achieve this in Play?


The other option you have for this, is to create an action in your controller that uses the @Before annotation, and then add the value using renderArgs().

I answered a previous question which I think is very similar to your requirements.

Does Play Framework support "snippets"?

You should also be aware that all session variables are available within your template, by default. You can see all the implicit objects that are available in the template in the Template Documentation here -- http://www.playframework.org/documentation/1.2.2/templates#implicits.


I need to stop answering my own questions.

I've created a tag as described in the link below, and it works perfectly:

http://www.playframework.org/documentation/1.2.2/templates#tags

0

精彩评论

暂无评论...
验证码 换一张
取 消