C
C
casey2011-09-28 16:32:33
symfony
casey, 2011-09-28 16:32:33

Where to generate common template data for similar pages in Symfony2?

I'm learning Symfony2 little by little and ran into this problem.
There are many similar pages on the site: all pages have a common header with the data of the current authorized user, half of the pages have a common right block with the latest news, and so on.
In my MVC development, there is a separate layer between the controller and the twig template - classes that received data dependent on user input from the controller and formed all the rest for the template. With their help, data about the current users and the latest news were formed, which the template then displayed.
The first thing that comes to mind is to make classes with static methods and call them from the controller, but maybe there is a better solution?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2011-09-28
@casey

Twig can call controller methods directly from the template. So if the conversation is about the latest news, then you can insert the latest news block somehow like this: The
{% render "AcmeDemoBundle:News:latest" %}
user is available in all templates through{{app.user}}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question