diff --git a/CHANGELOG-2.x.md b/CHANGELOG-2.x.md index 2f967c9..2d438ad 100644 --- a/CHANGELOG-2.x.md +++ b/CHANGELOG-2.x.md @@ -5,6 +5,9 @@ ### Removed - PHP v8.1 support +### Fixed +- Ifcontent will parse body even if content not existing [#0007231](https://bugs.oxid-esales.com/view.php?id=7231) + ## v2.4.0 - 2024-03-15 ### Added diff --git a/src/Node/IfContentNode.php b/src/Node/IfContentNode.php index 0cc03cb..121580f 100644 --- a/src/Node/IfContentNode.php +++ b/src/Node/IfContentNode.php @@ -46,7 +46,11 @@ public function compile(Compiler $compiler): void $compiler->raw(");\n"); $compiler + ->write("if(") + ->subcompile($this->getNode('variable'), false) + ->write(") { \n") ->subcompile($this->getNode('body')) + ->write(" } \n") ->write("unset(")->subcompile($this->getNode('variable'))->raw(");\n"); } } diff --git a/tests/Unit/Node/IfContentNodeTest.php b/tests/Unit/Node/IfContentNodeTest.php index f960aaa..c7d5a1e 100644 --- a/tests/Unit/Node/IfContentNodeTest.php +++ b/tests/Unit/Node/IfContentNodeTest.php @@ -50,7 +50,9 @@ public static function getOxidTwigTests(): array $tests[] = [$node, <<extensions['$ifContentExtensionClass']->getContent("oxsomething", null); +if(\$context["foo"]) { echo "Lorem Ipsum"; + } unset(\$context["foo"]); EOF ]; @@ -59,7 +61,9 @@ public static function getOxidTwigTests(): array $tests[] = [$node, <<extensions['$ifContentExtensionClass']->getContent(null, "oxsomething"); +if(\$context["foo"]) { echo "Lorem Ipsum"; + } unset(\$context["foo"]); EOF ];