View Issue Details

IDProjectCategoryView StatusLast Update
0007231OXID eShop (all versions)8. --- Twig engine ---public2024-11-08 11:14
Reporterckdot Assigned To 
PriorityhighSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
Product Version6.2.3 
Target Version7.0.1Fixed in Version7.2.0 
Summary0007231: ifcontent will parse body even if content not existing
DescriptionSee this smarty code:

[{oxifcontent ident="mycontenttemplate" object="oCont"}]
 foobar
[{/oxifcontent}]

-> foobar will not be displayed if mycontenttemplate does not exist, so oCont is false

See this twig code:

{% ifcontent ident "mycontenttemplate" set oCont %}
 foobar
{% endifcontent %}

-> foobar will be displayed even if oCont is false


why is that?
because you didn't add a condition before compiling the body in \OxidEsales\Twig\Node\IfContentNode::compile

quick fix:

replace

$compiler
            ->subcompile($this->getNode('body'))
            ->write("unset(")->subcompile($this->getNode('variable'))->raw(");\n");;

with:

 $compiler
            ->raw('if (')
            ->subcompile($this->getNode('variable'))
            ->raw(' !== false) {')
            ->subcompile($this->getNode('body'))
            ->write("unset(")->subcompile($this->getNode('variable'))->raw(");\n")
            ->raw('}');
TagsTwig
ThemeAll
BrowserAll
PHP VersionAll
Database VersionAll

Relationships

related to 0007552 confirmedHR The Twig-Function ifcontents doesn't work as the theme intends it. 

Activities

QA

2021-04-23 09:31

administrator   ~0013429

-MK

QA

2023-07-03 14:53

administrator   ~0015397

Last edited: 2023-07-03 14:54

Tested in 7.0.0
Bug still reproducable
- mko

tode

2024-06-13 09:30

reporter   ~0017040

Unfortunately still reproduceable in version 7.1.0.
The mentioned fix works fine.
Please fix it with the next bugfix release. Otherwise it has to be patched with every release.

(Bug also reported in 0007552)