Skip to content

Commit

Permalink
Merge branch 'b-7.2.x-OXDEV-7203' into b-7.2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
tkcreateit committed Sep 6, 2024
2 parents 0f89acc + 6c639be commit 6f647e3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG-2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/Node/IfContentNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
4 changes: 4 additions & 0 deletions tests/Unit/Node/IfContentNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public static function getOxidTwigTests(): array
$tests[] = [$node, <<<EOF
// line 1
\$context["foo"] = \$this->extensions['$ifContentExtensionClass']->getContent("oxsomething", null);
if(\$context["foo"]) {
echo "Lorem Ipsum";
}
unset(\$context["foo"]);
EOF
];
Expand All @@ -59,7 +61,9 @@ public static function getOxidTwigTests(): array
$tests[] = [$node, <<<EOF
// line 1
\$context["foo"] = \$this->extensions['$ifContentExtensionClass']->getContent(null, "oxsomething");
if(\$context["foo"]) {
echo "Lorem Ipsum";
}
unset(\$context["foo"]);
EOF
];
Expand Down

0 comments on commit 6f647e3

Please sign in to comment.