Merge branch '2.x' into 3.x

* 2.x:
  do not clean up whitespace text nodes inside if tags
This commit is contained in:
Fabien Potencier
2022-12-26 20:36:12 +01:00
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))
->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')) {
+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