Skip to content

Commit

Permalink
do not clean up whitespace text nodes inside if tags
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh authored and fabpot committed Dec 26, 2022
1 parent 6cd1473 commit c8ec092
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Node/IfNode.php
Expand Up @@ -50,8 +50,11 @@ public function compile(Compiler $compiler)
->subcompile($this->getNode('tests')->getNode($i))
->raw(") {\n")
->indent()
->subcompile($this->getNode('tests')->getNode($i + 1))
;
// The node might not exists if the content is empty
if ($this->getNode('tests')->hasNode($i + 1)) {
$compiler->subcompile($this->getNode('tests')->getNode($i + 1));
}
}

if ($this->hasNode('else')) {
Expand Down
32 changes: 32 additions & 0 deletions tests/Fixtures/tags/if/empty_body.test
@@ -0,0 +1,32 @@
--TEST--
empty "if" body in child template
--TEMPLATE--
{% extends 'base.twig' %}

{% set foo = '' %}

{% if a is defined %}

{% else %}
{% set foo = 'NOTHING' %}
{% endif %}

{% if a is defined %}

{% endif %}

{% if a is defined %}
{% set foo = 'NOTHING' %}
{% else %}

{% endif %}

{% block content %}
{{ foo }}
{% endblock %}
--TEMPLATE(base.twig)--
{% block content %}{% endblock %}
--DATA--
return []
--EXPECT--
NOTHING

0 comments on commit c8ec092

Please sign in to comment.