David David - 1 year ago 154
Twig Question

Symfony2: pass parameter to all views

I want to display the user name/last connection date/time and some other info on all of my twig views (which all extend a common twig layout).

How can I achieve that without having to explicitely pass those parameters from each controller to each view ?

Do I have to create a twig extension, or make a call to a controller/action that will retrieve username/connection/other info from the layout using render?

I'd like a simpler solution if possible.


1ed 1ed
Answer Source

User is accessible as a predefined global variable, take a look at this, and if you want to reuse the same template fragment in all your templates take a look at the include tag.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download