mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-12 10:26:32 +00:00
fixed render block with template wrapper
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user