mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-16 12:26:30 +00:00
fixed template_from_string when the template includes or extends other ones
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
* 1.14.0 (2013-XX-XX)
|
* 1.14.0 (2013-XX-XX)
|
||||||
|
|
||||||
|
* fixed template_from_string when the template includes or extends other ones
|
||||||
* added support for calling macros defined in a template without importing them first
|
* added support for calling macros defined in a template without importing them first
|
||||||
* added support for named arguments for macros
|
* added support for named arguments for macros
|
||||||
* replaced a PHP fatal error with an exception when a macro does not exist
|
* replaced a PHP fatal error with an exception when a macro does not exist
|
||||||
|
|||||||
@@ -43,16 +43,14 @@ class Twig_Extension_StringLoader extends Twig_Extension
|
|||||||
*/
|
*/
|
||||||
function twig_template_from_string(Twig_Environment $env, $template)
|
function twig_template_from_string(Twig_Environment $env, $template)
|
||||||
{
|
{
|
||||||
static $loader;
|
$loader = new Twig_Loader_Chain(array(
|
||||||
|
new Twig_Loader_Array(array('__string_template__' => $template)),
|
||||||
|
$current = $env->getLoader(),
|
||||||
|
));
|
||||||
|
|
||||||
if (null === $loader) {
|
|
||||||
$loader = new Twig_Loader_String();
|
|
||||||
}
|
|
||||||
|
|
||||||
$current = $env->getLoader();
|
|
||||||
$env->setLoader($loader);
|
$env->setLoader($loader);
|
||||||
try {
|
try {
|
||||||
$template = $env->loadTemplate($template);
|
$template = $env->loadTemplate('__string_template__');
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$env->setLoader($current);
|
$env->setLoader($current);
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,12 @@
|
|||||||
{% include template_from_string(template) %}
|
{% include template_from_string(template) %}
|
||||||
|
|
||||||
{% include template_from_string("Hello {{ name }}") %}
|
{% include template_from_string("Hello {{ name }}") %}
|
||||||
|
{% include template_from_string('{% extends "parent.twig" %}{% block content %}Hello {{ name }}{% endblock %}') %}
|
||||||
|
--TEMPLATE(parent.twig)--
|
||||||
|
{% block content %}{% endblock %}
|
||||||
--DATA--
|
--DATA--
|
||||||
return array('name' => 'Fabien', 'template' => "Hello {{ name }}")
|
return array('name' => 'Fabien', 'template' => "Hello {{ name }}")
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
Hello Fabien
|
Hello Fabien
|
||||||
Hello Fabien
|
Hello Fabien
|
||||||
|
Hello Fabien
|
||||||
|
|||||||
Reference in New Issue
Block a user