Add custom user information to twig service provider silex -


I am using the syllax framework for my project. I am using SecurityServiceProvider with a custom user implementation Login / logout works and I'm able to see the correct user information in the Symphony Profiler (stored as session attributes). Now I am trying to add custom user information to the tribune environment so that templates can be accessed. Here's how I came from:

  $ app ['twig'] = $ app- & gt; Share ($ app- & gt; Extensions ('twig', function, $ app) {$ token = $ app ['security'] - & gt; getToken (); $ user INFO = null; if (empty! = = $ Token) {$ userInfo = $ token-> getUser () -> GetTwigInfo ();} $ twig-> AddGlobal ('userinfo', $ userInfo); return $ twig;}));  

I am trying to extend the environment and it works, though user information is processed later and my userinfo attribute is always null. I think I'll have to expand the atmosphere of a stroll somehow, but it does not know at all how can I help someone?

Silux gives you access directly to the app example by Toggle.

Then you can do this:

  {{app.security.token? App.security.token.user.twigInfo: null}}  

or

  {% set userinfo = app.security.token? App.security.token.user.twigInfo: null%} {{userinfo}}  

If you want to handle it within your PHP code, you can create a new definition

$ app ['userinfo'] = $ app- & gt; Share ($ app) {$ token = $ app ['security'] - & gt; getToken (); return (empty! = = $ Token)? $ Token- & gt; getUser () - & gt; GetTwigInfo (): null;}));

Then in your jogging template

  {{app.userinfo}}  

Comments