Skip to content

Commit

Permalink
Merge pull request #7 from m-vo/bugfix/fe-page-caching
Browse files Browse the repository at this point in the history
Fix fe_* templates not setting cache headers
  • Loading branch information
m-vo authored Feb 28, 2021
2 parents 0ba8d6b + 1db779d commit a82bc2e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/EventListener/RenderingForwarder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class RenderingForwarder
{
private const TWIG_TEMPLATE = 'twig_template';
private const TEMPLATE_CONTEXT = 'context';
private const CONTAO_TEMPLATE = 'contao_template';

private Environment $twig;
private TemplateLocator $templateLocator;
Expand Down Expand Up @@ -79,7 +80,8 @@ public function registerTemplates(): void
*/
public function delegateRendering(Template $contaoTemplate): void
{
$template = $this->templates[$contaoTemplate->getName()] ?? null;
$originalName = $contaoTemplate->getName();
$template = $this->templates[$originalName] ?? null;

if (null === $template) {
return;
Expand All @@ -91,6 +93,7 @@ public function delegateRendering(Template $contaoTemplate): void
$contaoTemplate->setData([
self::TWIG_TEMPLATE => $template,
self::TEMPLATE_CONTEXT => $contaoTemplate->getData(),
self::CONTAO_TEMPLATE => $originalName,
]);
}

Expand All @@ -100,6 +103,11 @@ public function render(Template $contaoTemplate): string

$template = $data[self::TWIG_TEMPLATE] ?? null;
$context = $data[self::TEMPLATE_CONTEXT] ?? null;
$originalName = $data[self::CONTAO_TEMPLATE] ?? '';

// restore old template name, so that FrontendTemplate sets the right
// cache headers in case of fe_* templates
$contaoTemplate->setName($originalName);

// restore old template context, so that legacy modules are happy
// (e.g. ModuleNavigation is checking for Template->items)
Expand Down
1 change: 1 addition & 0 deletions tests/EventListener/RenderingForwarderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function testSetsProxyTemplate(): void
->with([
'twig_template' => 'sub/bar.html.twig',
'context' => ['a' => 123],
'contao_template' => 'bar',
]);

$renderingForwarder->delegateRendering($template);
Expand Down

0 comments on commit a82bc2e

Please sign in to comment.