A
A
Alexander Strelov2012-12-13 11:37:25
symfony
Alexander Strelov, 2012-12-13 11:37:25

How to implement a block structure project in Symfony?

I recently started studying Symfony 2, maybe I didn’t understand something fundamentally, please help me in solving the problem: It is
necessary to implement modular project loading, i.e. menu, authorization form, news feed, list of users and other blocks on the site. As far as I understand, it is necessary to define the router and write the appropriate handler in the controller, it will give out data for the twig template, which will be displayed to the user. But it's not clear to me how to combine different functional blocks with different templates and different routers into one lauout in order to collect them all.
I know it's possible to "inherit" twig templates, but if I define my template as a piece of the base layuot, when I call the router for that template, how will other templates be loaded if my controller only returns data for my template? I need to separate the blocks from each other as much as possible so that they do not depend on others.
Now I need to integrate the login form from FOSUserBundle with other blocks of the site, I created a child bundle from FOSUserBundle, but I don’t know where to go next. I found the SonataBlock bundle but I can’t figure out if it is needed at all in this case or not. Please help those who are strong in this.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Inori, 2012-12-13
@pokupo

Twig has a function renderfor exactly this need
Example:

{% render 'AcmeDemoBundle:User:login' %}

Symfony2 will make a request to UserController::loginAction(), which will be responsible for preparing and rendering the template with the login form.
Example from a real project: github.com/KnpLabs/KnpBundles/blob/master/src/Knp/Bundle/KnpBundlesBundle/Resources/views/layout.html.twig#L35
github.com/KnpLabs/KnpBundles/blob/master/src/ Knp/Bundle/KnpBundlesBundle/Controller/DeveloperController.php#L25-#L33

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question