mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-15 20:06:31 +00:00
merged branch fabpot/complex-template_from_string (PR #1154)
This PR was merged into the master branch.
Discussion
----------
fixed template_from_string when the template includes or extends other ones
This should fix #1134
Commits
-------
1b5bf91 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)
|
||||
|
||||
* fixed template_from_string when the template includes or extends other ones
|
||||
* improved the performance of the filesystem loader
|
||||
* fixed a crash of the C extension on an edge case
|
||||
* fixed the filesystem loader cache when a template name exists in several namespaces
|
||||
|
||||
@@ -43,16 +43,14 @@ class Twig_Extension_StringLoader extends Twig_Extension
|
||||
*/
|
||||
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);
|
||||
|
||||
|
||||
@@ -4,8 +4,12 @@
|
||||
{% 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
|
||||
|
||||
Reference in New Issue
Block a user