* 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 named arguments for macros
* replaced a PHP fatal error with an exception when a macro does not exist
*/
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);
try {
- $template = $env->loadTemplate($template);
+ $template = $env->loadTemplate('__string_template__');
} catch (Exception $e) {
$env->setLoader($current);
{% include template_from_string(template) %}
{% 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--
return array('name' => 'Fabien', 'template' => "Hello {{ name }}")
--EXPECT--
Hello Fabien
Hello Fabien
+Hello Fabien