From 17d1786e5c5add04aa400ee2eab7b9f2409ae413 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Thu, 29 Jul 2021 16:12:14 +0300 Subject: [PATCH] Fixed broken Twig try tag when catch has not been defined or is empty --- CHANGELOG.md | 1 + .../Grav/Common/Twig/Node/TwigNodeTryCatch.php | 15 +++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5467bd8c..31f12f0af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * Fixed GPM not using non-standard cache path [#3410](https://github.com/getgrav/grav/issues/3410) * Fixed broken `environment://` stream when it doesn't have configuration * Fixed `Flex Object` missing key field value when using `FolderStorage` + * Fixed broken Twig try tag when catch has not been defined or is empty # v1.7.18 ## 07/19/2021 diff --git a/system/src/Grav/Common/Twig/Node/TwigNodeTryCatch.php b/system/src/Grav/Common/Twig/Node/TwigNodeTryCatch.php index da95a1d98..40e9240f3 100644 --- a/system/src/Grav/Common/Twig/Node/TwigNodeTryCatch.php +++ b/system/src/Grav/Common/Twig/Node/TwigNodeTryCatch.php @@ -49,16 +49,15 @@ class TwigNodeTryCatch extends Node $compiler ->indent() - ->subcompile($this->getNode('try')); + ->subcompile($this->getNode('try')) + ->outdent() + ->write('} catch (\Exception $e) {' . "\n") + ->indent() + ->write('if (isset($context[\'grav\'][\'debugger\'])) $context[\'grav\'][\'debugger\']->addException($e);' . "\n") + ->write('$context[\'e\'] = $e;' . "\n"); if ($this->hasNode('catch')) { - $compiler - ->outdent() - ->write('} catch (\Exception $e) {' . "\n") - ->indent() - ->write('if (isset($context[\'grav\'][\'debugger\'])) $context[\'grav\'][\'debugger\']->addException($e);' . "\n") - ->write('$context[\'e\'] = $e;' . "\n") - ->subcompile($this->getNode('catch')); + $compiler->subcompile($this->getNode('catch')); } $compiler