简体   繁体   中英

Java Play Framework Global Variables

I am currently "Playing" With the Java Play Framework and would like to know a simple solution to having an online status on the main.html page (this page will be consistent throughout the site eg navigation bar, header and footer). At the top of this page I would like an online status for users that are signed in, I am yet to implement authentication as I will probably use an already existing play module to do this. My concern is that would I have to send a variable through to the main.html for every page I implement with this online status.

My main question is how do you store globally accessible variables in play?

Thanks

The renderArgs are available in inherited templates (main.html), so you don't need to pass them with the #{set} tag. Additionally, if you use a @Before method in a superclass of your controller, you could have it populate the renderArgs with the global value. So you'd only have to set it once to make it available in main.html for all of your pages.

我通过编写FastTag来获取所需信息,从而做了类似的事情。

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