How to use the RequestAnalyzer with ESI requests?¶
The symfony documentation already describes how to use edge side includes
to cache parts of pages with different life times. However, if you are using
the render_esi
function in combination with the controller
function as
shown in the following code, you might encounter issues:
{{ render_esi(controller('AppBundle:News:latest', { 'maxPerPage': 5 })) }}
This will probably work for most controllers, but if the latestAction
of
the NewsController
makes use of the RequestAnalyzer
it might fail,
because the RequestAnalyzer
can’t analyze the request. This is caused by
the fact that Symfony generates a special URL for this render_esi
call.
The solution to this problem is to also pass the portal and the locale (if the rendered content should not have the same locale as the rest of the page) to the options:
{{ render_esi(controller('AppBundle:News:latest', { 'maxPerPage': 5, _portal: request.portalKey, _locale: request.locale })) }}