Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OXDEV-7203 IfcontentNode must only parse body for existing content #9

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading