diff --git a/lib/Twig/TemplateWrapper.php b/lib/Twig/TemplateWrapper.php index 643a493d4..9589bbc85 100644 --- a/lib/Twig/TemplateWrapper.php +++ b/lib/Twig/TemplateWrapper.php @@ -87,20 +87,6 @@ final class Twig_TemplateWrapper * @return string The rendered block */ public function renderBlock($name, $context = array()) - { - ob_start(); - $this->displayBlock($name, $context); - - return ob_get_clean(); - } - - /** - * Displays a template block. - * - * @param string $name The block name to render - * @param array $context An array of parameters to pass to the template - */ - public function displayBlock($name, $context = array()) { $context = $this->env->mergeGlobals($context); $level = ob_get_level(); @@ -124,6 +110,17 @@ final class Twig_TemplateWrapper return ob_get_clean(); } + /** + * Displays a template block. + * + * @param string $name The block name to render + * @param array $context An array of parameters to pass to the template + */ + public function displayBlock($name, $context = array()) + { + $this->template->displayBlock($name, $this->env->mergeGlobals($context)); + } + /** * @return Twig_Source */ diff --git a/test/Twig/Tests/TemplateWrapperTest.php b/test/Twig/Tests/TemplateWrapperTest.php index fbc4b4a20..9cd1ced9a 100644 --- a/test/Twig/Tests/TemplateWrapperTest.php +++ b/test/Twig/Tests/TemplateWrapperTest.php @@ -35,4 +35,30 @@ class Twig_Tests_TemplateWrapperTest extends PHPUnit_Framework_TestCase $this->assertTrue($wrapper->hasBlock('extended')); $this->assertEquals(array('foo', 'extended'), $wrapper->getBlockNames()); } + + public function testRenderBlock() + { + $twig = new Twig_Environment(new Twig_Loader_Array(array( + 'index' => '{% block foo %}{{ foo }}{{ bar }}{% endblock %}', + ))); + $twig->addGlobal('bar', 'BAR'); + + $wrapper = new Twig_TemplateWrapper($twig, $twig->loadTemplate('index')); + $this->assertEquals('FOOBAR', $wrapper->renderBlock('foo', array('foo' => 'FOO'))); + } + + public function testDisplayBlock() + { + $twig = new Twig_Environment(new Twig_Loader_Array(array( + 'index' => '{% block foo %}{{ foo }}{{ bar }}{% endblock %}', + ))); + $twig->addGlobal('bar', 'BAR'); + + $wrapper = new Twig_TemplateWrapper($twig, $twig->loadTemplate('index')); + + ob_start(); + $wrapper->displayBlock('foo', array('foo' => 'FOO')); + + $this->assertEquals('FOOBAR', ob_get_clean()); + } }