Search code examples
springmodel-view-controllercontrollerjtwig

Is it possible to inject HttpSession object in each view JTwig and Spring MVC


I am using SpringMVC with JTwig view system and I want to be able to access the session scope (HttpSession) from all my views ( to know if I have to display the logout link for exemple ).

Thanks you very much.


Solution

  • This is supported by Jtwig natively. As per Jtwig documentation you can do the following:

    {% if ((app.request.session.attributeName) is defined) %}
    Hello
    {% endif %}
    

    To print Hello if the session attribute attributeName exists.