-
Notifications
You must be signed in to change notification settings - Fork 1
Embedding controllers
It is possible to have a fragment render from invoking an MVC call through Symfony2. This allows you to extend past the basic behaviour of a listener and invoke new controllers and bundles that exist outside standard CMS functionality.
You can use Fragment and Node listeners that will listen to events that are triggered by the dispatcher service. The listeners can easily interact with other service, read the request, load database calls/etc and inject context view data into the fragment. This can be easily read in from the twig template.
In some cases, you may want to break out of using this approach and use an embedded MVC triad, known as the hierarchal MVC model or H-MVC.
The CMS is in itself a hierarchal composition of fragments that are assigned to regions within another fragment. When encountering a fragment, an associated twig template is loaded as a place to create the view presentation of the fragment content.
Instead of rendering the content of the fragment through this particular view, you can invoke a {% render %}
to call the controller of your choice.
If you would like to leverage a standard controller to draw out a form or more complex structure, first start by establishing your Model/View/Controller. Once that you have created the necessary action to be invoked, you will need to edit the view for the contact form, and embed the {% render %}
call that will call your controller.
Example: Fragment template that invokes another controller
{% render "ClientWebsiteBundle:Default:index" with {'foo':'bar'} %}