do not clean up whitespace text nodes inside if tags

This commit is contained in:
Christian Flothmann
2022-08-12 19:15:06 +02:00
committed by Fabien Potencier
parent 6cd1473d65
commit c8ec092ceb
2 changed files with 36 additions and 1 deletions
+4 -1
View File
@@ -50,8 +50,11 @@ class IfNode extends Node
->subcompile($this->getNode('tests')->getNode($i)) ->subcompile($this->getNode('tests')->getNode($i))
->raw(") {\n") ->raw(") {\n")
->indent() ->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')) { if ($this->hasNode('else')) {
+32
View File
@@ -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