0
votes

I am evaluating if I want to use symfony2 and twig for a project I have coming up, I am very new to the symfony2/Twig world, have been primarily building out the framework for each of our sites one by one. My primary question is if I am using a base twig template, That all of my pages are inheriting from is it possible for that base page to have its own controller? as well as the child page to have its own controller?

So for example if the header had some dynamic content that the logic would never change I wouldn't need to replace that logic in the front controller of every page, but the content block would be generated in the front controller.

I will have multiple developers on the project and to be honest if I can have them writing very little amounts of conde after I configure the project that would be fantastic.

EX:

<!-- Very Simplified example:baseTemplate -->
<body>
    <div id="headerContainer">
         {% block headerBlock %}{% endblock %}
    </div>
    <div id="bodyContainer">
         {% block bodyBlock %}{% endblock %}
    </div>
    <div id="footerContainer">
         {% block footerBlock %}{% endblock %}
    </div>
 </body>

Another way I have contemplated doing this is by building a class that extends the controller class and having functions that will handle this code for the other developers and they can just call them when rendering the template.

How would you handle this? Once again I am by no means a seasoned Symfony developer so looking more at best practices as well as if it's possible.

1

1 Answers

0
votes

The best way to do this is to use DI container, for example if you want to create complex menu, you can use KnpLabs/KnpMenuBundle, create MenuBuilder and use it from controller where you need it. Here you can find more examples:

http://knpuniversity.com/screencast/question-answer-day/symfony2-users-menu-cms#menus

Good luck =)