David David - 4 months ago 83
Twig Question

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

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.