Add config to enable Twig strict_variables (#3370)

Adds the cms.enableTwigStrictVariables config option to enable strict_variables in Twig for debugging purposes. See https://twig.symfony.com/doc/2.x/api.html#environment-options. Credit to @matteotrubini
This commit is contained in:
Matteo 2018-01-26 17:59:45 +01:00 committed by Luke Towers
parent cf01254b2b
commit 678916854e
2 changed files with 18 additions and 0 deletions

View File

@ -347,4 +347,19 @@ 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,
];

View File

@ -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) {