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 ];