From f9cd7e12a853b272b4bfb93a9e396bc38550ea24 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Sun, 3 Jul 2022 19:08:53 -0400 Subject: [PATCH 1/2] fix twig environment; credit to @RomainMazB --- modules/cms/classes/Controller.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/cms/classes/Controller.php b/modules/cms/classes/Controller.php index a89a1c957e..c5a9e7775c 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -584,6 +584,7 @@ protected function postProcessResult($page, $url, $content) protected function initTwigEnvironment() { $this->twig = App::make('twig.environment.cms'); + $this->twig->addGlobal('this', ['controller' => $this]); } /** From 101c68b0dc9b1972228a9b0478d646e3097c1496 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Sun, 3 Jul 2022 21:21:37 -0400 Subject: [PATCH 2/2] document the *hack* Co-authored-by: Luke Towers --- modules/cms/classes/Controller.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/cms/classes/Controller.php b/modules/cms/classes/Controller.php index c5a9e7775c..b0119ac5b0 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -584,6 +584,9 @@ protected function postProcessResult($page, $url, $content) protected function initTwigEnvironment() { $this->twig = App::make('twig.environment.cms'); + // Ensure that $this['controller'] is available at all times in the base Twig context + // so that CMS Twig functions (in Cms\Twig\Extension) work inside of Macros + // @see https://github.com/wintercms/winter/issues/578 $this->twig->addGlobal('this', ['controller' => $this]); }