mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-31 12:37:15 +00:00
Merge branch '1.x' into 2.x
* 1.x: fixed import macros from a template string
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ class ImportNode extends Node
|
||||
->repr($this->getTemplateName())
|
||||
->raw(', ')
|
||||
->repr($this->getTemplateLine())
|
||||
->raw(')')
|
||||
->raw(')->unwrap()')
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
];
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user