Thursday, 15 July 2010

symfony - Change Twig Content depending on existing session -


Currently I'm working on Symphony Web-project. At the moment I have a layout.html.twig file that sets a navigation bar and is extended by any other .html.twig file.

Recently I implemented a user login area based on whether or not now logged in or not, I want to dynamically change the contents of that navigation bar. Since I can not write php code directly in a .html.twig file, so I can not use session variables.

What will be the best practice to achieve this?

Thanks in advance!

You can check the user's status like

  { % If app.user%} & lt; Div class = "loggedInNav" & gt; & Lt; / Div & gt; {% Else%} & lt; Div class = "notLoggedInNav" & gt; & Lt; / Div & gt; {% Endif%}  

No comments:

Post a Comment