Merge branch '1.x' into 2.x

* 1.x:
  fixed a regression
This commit is contained in:
Fabien Potencier
2019-05-16 20:18:06 +02:00
4 changed files with 81 additions and 1 deletions
+9 -1
View File
@@ -279,7 +279,15 @@ class Parser
public function getImportedSymbol($type, $alias)
{
return $this->importedSymbols[0][$type][$alias] ?? null;
if (null !== $this->peekBlockStack()) {
foreach ($this->importedSymbols as $functions) {
if (isset($functions[$type][$alias])) {
return $functions[$type][$alias];
}
}
} else {
return $this->importedSymbols[0][$type][$alias] ?? null;
}
}
public function isMainScope()
@@ -0,0 +1,18 @@
--TEST--
"macro" tag
--TEMPLATE--
{% block foo %}
{%- from _self import input as linput %}
{% endblock %}
{% block bar %}
{{- linput('username') }}
{% endblock %}
{% macro input(name) -%}
<input name="{{ name }}">
{% endmacro %}
--DATA--
return []
--EXCEPTION--
Twig\Error\SyntaxError: Unknown "linput" function in "index.twig" at line 7.
@@ -0,0 +1,36 @@
--TEST--
"macro" tag
--TEMPLATE--
{% import _self as macros %}
{% from _self import input %}
{% block foo %}
{{- macros.input('username') }}
{{- input('username') }}
{%- import _self as lmacros %}
{%- from _self import input as linput %}
{{- lmacros.input('username') }}
{{- linput('username') }}
{% endblock %}
{% block bar %}
{{- macros.input('username') }}
{{- input('username') }}
{% endblock %}
{% macro input(name) -%}
<input name="{{ name }}">
{% endmacro %}
--DATA--
return []
--EXPECT--
<input name="username">
<input name="username">
<input name="username">
<input name="username">
<input name="username">
<input name="username">
@@ -0,0 +1,18 @@
--TEST--
"macro" tag
--TEMPLATE--
{% block foo %}
{%- import _self as lmacros %}
{% endblock %}
{% block bar %}
{{- lmacros.input('username') }}
{% endblock %}
{% macro input(name) -%}
<input name="{{ name }}">
{% endmacro %}
--DATA--
return []
--EXCEPTION--
Twig\Error\RuntimeError: Variable "lmacros" does not exist in "index.twig" at line 7.