Excerpt | |||||
---|---|---|---|---|---|
|
Table of Contents |
---|
Enhanced views for Content/Location
In some cases, displaying a content Content item/location Location via the built-in ViewController
is not sufficient and will lead force you to do make many sub-requests in order to access different parameters.
...
- Settings (either coming from
ConfigResolver
orServiceContainer
) - Current contentContent item's
ContentType
object - Current locationLocation's parent
- Current locationLocation's children count
- Main location Location and alternative locations Locations for the current contentContent item
- etc…etc.
In those cases, you may want to use your own controller to display the current contentContent item/location Location instead of using the built-in ViewController
.
...
Info |
---|
You can point to any kind of controller supported by Symfony (including controllers as a service). |
The only requirement here is that your action method has a similar signature than ViewController::viewLocation()
or or ViewController::viewContent()
(depending on what you're matching of course). However, note that all arguments are not mandatory since Symfony is clever enough to know what to inject in into your action method . Hence That is why you aren're not t forced to mimic the ViewController
's signature strictly. For example, if you omit $layout
and $params
arguments, it will still be still valid. Symfony will just avoid to inject injecting them in into your action method.
Original ViewController signatures
...
Warning | ||
---|---|---|
| ||
Using your own controller, it is your responsibility to define cache rules, like for every custom controller ! So don't forget to set cache rules and the appropriate See built-in ViewController for more details on this. |
...
Tip |
---|
This is usually the recommended way to use a custom controller. |
Note |
---|
Always ensure to that you add new parameters to existing |
...
Note |
---|
Always ensure to have a Not doing so (e.g. only passing your custom parameters array) can result with in unexpected issues with content preview. Previewed content and other parameters are indeed passed in |
...
One other way to keep control on of what is passed to the view is to use your own controller instead of the built-in ViewController.
...