Skip to content

Commit

Permalink
OXDEV-7203 IfcontentNode must only parse body for existing content
Browse files Browse the repository at this point in the history
  • Loading branch information
hkreuter committed Jul 3, 2024
1 parent 7a40538 commit 6c639be
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG-2.x.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log for OXID Twig engine component

## [Undecided] - unreleased

### 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 6c639be

Please sign in to comment.