diff --git a/modules/cms/classes/Controller.php b/modules/cms/classes/Controller.php index a89a1c957e..b0119ac5b0 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -584,6 +584,10 @@ 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]); } /**