How to use a custom controller to display a content item ...
Versions Compared
Old Version 2
changes.mady.by.user Dominika Kurek
Saved on Dec 15, 2015
compared with
New Version Current
changes.mady.by.user Dominika Kurek
Saved on Feb 01, 2016
Key
- This line was added.
- This line was removed.
- Formatting was changed.
| 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 or ServiceContainer)
- 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 X-Location-Id header in the returned Response object. 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 $params associative array, using + union operator or array_merge() . 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 $params. |
...
| Note |
|---|
| Always ensure to have a $params argument and to add new parameters to it, using + union operator or array_merge() . 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 $params. |
...
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.
...
Comments
Add a comment