user1071584
user1071584

Reputation: 41

Play framework 2.0 renderArgs alternative

I have a question about the renderArgs variable and where it is in the play framework 2.0 for either Java and scala. As far as I understand templates are now called with explicit arguments. You explicitly add the beans to your view, e.g.:

views.html.Application.index.render(customer, orders);

I am asking this for a specific user case I use in a current Play framework app. All controllers are annotated with @With which implements a simple lookup if the username is in the session it loads the user account from the db and puts this in the renderArgs object.

Then the controller or the view can access this bean if needed. Very DRY. It seems as if play framework 2.0 seriously undermines this, having to explicitly add the account bean to each view call, e.g.:

views.html.Application.index.render(account, customer, orders);

Any advise? Any functionality for this available but not yet in the documentation?

Upvotes: 4

Views: 1586

Answers (1)

Pere Villega
Pere Villega

Reputation: 16439

You can use implicit variables.

This answer solves a tangential issue, but the idea is to declare an implicit variable and make it available on scope so you don't have to pass it around.

Upvotes: 2

Related Questions