josef.van.niekerk
josef.van.niekerk

Reputation: 12121

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

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

String sessionId = Scope.Session.current().getId();
Cache.set(sessionId + "_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?

Upvotes: 0

Views: 1008

Answers (2)

Codemwnci
Codemwnci

Reputation: 54924

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.

Upvotes: 3

josef.van.niekerk
josef.van.niekerk

Reputation: 12121

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

Upvotes: 0

Related Questions