diff --git a/config/cms.php b/config/cms.php index 5c35ca4f3..088323b50 100644 --- a/config/cms.php +++ b/config/cms.php @@ -346,5 +346,20 @@ return [ */ 'forceBytecodeInvalidation' => true, + + /* + |-------------------------------------------------------------------------- + | Twig Strict Variables + |-------------------------------------------------------------------------- + | + | If strict_variables is disabled, Twig will silently ignore invalid + | variables (variables and or attributes/methods that do not exist) and + | replace them with a null value. When enabled, Twig throws an exception + | instead. If set to null, it is enabled when debug mode (app.debug) is + | enabled. + | + */ + + 'enableTwigStrictVariables' => false, ]; diff --git a/modules/cms/classes/Controller.php b/modules/cms/classes/Controller.php index dc67dce66..f3bdb2d91 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -488,11 +488,14 @@ class Controller $useCache = !Config::get('cms.twigNoCache'); $isDebugMode = Config::get('app.debug', false); + $strictVariables = Config::get('cms.enableTwigStrictVariables', false); + $strictVariables = is_null($strictVariables) ? $isDebugMode : $strictVariables; $forceBytecode = Config::get('cms.forceBytecodeInvalidation', false); $options = [ 'auto_reload' => true, 'debug' => $isDebugMode, + 'strict_variables' => $strictVariables, ]; if ($useCache) {