Merge branch '1.x' into 2.x

* 1.x:
  fixed import macros from a template string
This commit is contained in:
Fabien Potencier
2019-04-22 18:01:41 +02:00
7 changed files with 37 additions and 3 deletions
+1
View File
@@ -213,6 +213,7 @@
* 1.39.2 (2019-XX-XX)
* fixed Lexer when using custom options containing the # char
* fixed "import" when macros are stored in a template string
* 1.39.1 (2019-04-16)
+1 -1
View File
@@ -46,7 +46,7 @@ class ImportNode extends Node
->repr($this->getTemplateName())
->raw(', ')
->repr($this->getTemplateLine())
->raw(')')
->raw(')->unwrap()')
;
}
+13
View File
@@ -301,6 +301,9 @@ abstract class Template
return array_unique($names);
}
/**
* @return Template|TemplateWrapper
*/
protected function loadTemplate($template, $templateName = null, $line = null, $index = null)
{
try {
@@ -341,6 +344,16 @@ abstract class Template
}
}
/**
* @internal
*
* @return Template
*/
protected function unwrap()
{
return $this;
}
/**
* Returns all blocks.
*
+10
View File
@@ -126,6 +126,16 @@ final class TemplateWrapper
{
return $this->template->getTemplateName();
}
/**
* @internal
*
* @return Template
*/
public function unwrap()
{
return $this->template;
}
}
class_alias('Twig\TemplateWrapper', 'Twig_TemplateWrapper');
@@ -0,0 +1,10 @@
--TEST--
"import" tag with a template as string
--TEMPLATE--
{% import template_from_string("{% macro test() %}ok{% endmacro %}") as m %}
{{ m.test() }}
--TEMPLATE(forms.twig)--
--DATA--
return []
--EXPECT--
ok
+1 -1
View File
@@ -36,7 +36,7 @@ class Twig_Tests_Node_ImportTest extends NodeTestCase
$tests[] = [$node, <<<EOF
// line 1
\$context["macro"] = \$this->loadTemplate("foo.twig", null, 1);
\$context["macro"] = \$this->loadTemplate("foo.twig", null, 1)->unwrap();
EOF
];
+1 -1
View File
@@ -156,7 +156,7 @@ class __TwigTemplate_%x extends \Twig\Template
protected function doDisplay(array \$context, array \$blocks = [])
{
// line 2
\$context["macro"] = \$this->loadTemplate("foo.twig", "foo.twig", 2);
\$context["macro"] = \$this->loadTemplate("foo.twig", "foo.twig", 2)->unwrap();
// line 1
\$this->parent = \$this->loadTemplate("layout.twig", "foo.twig", 1);
\$this->parent->display(\$context, array_merge(\$this->blocks, \$blocks));