renderTemplate example

protected function parseTemplate(string $class, array $search = [], array $replace = [], array $data = []): string
    {
        // Retrieves the namespace part from the fully qualified class name.         $namespace = trim(implode('\\', array_slice(explode('\\', $class), 0, -1)), '\\');
        $search[]  = '<@php';
        $search[]  = '{namespace}';
        $search[]  = '{class}';
        $replace[] = '<?php';
        $replace[] = $namespace;
        $replace[] = str_replace($namespace . '\\', '', $class);

        return str_replace($search$replace$this->renderTemplate($data));
    }

    /** * Builds the contents for class being generated, doing all * the replacements necessary, and alphabetically sorts the * imports for a given template. */
    protected function buildContent(string $class): string
    {
        $template = $this->prepare($class);

        
use Twig\Environment;
use Twig\Loader\ArrayLoader;
use Twig\RuntimeLoader\RuntimeLoaderInterface;

class HttpKernelExtensionTest extends TestCase
{
    public function testFragmentWithError()
    {
        $this->expectException(\Twig\Error\RuntimeError::class);
        $renderer = $this->getFragmentHandler($this->throwException(new \Exception('foo')));

        $this->renderTemplate($renderer);
    }

    public function testRenderFragment()
    {
        $renderer = $this->getFragmentHandler($this->returnValue(new Response('html')));

        $response = $this->renderTemplate($renderer);

        $this->assertEquals('html', $response);
    }

    
/** * Renders the Enlight_Template_Default of the Enlight_View_Default * which is set in the Enlight_Controller_Action. * * @return Enlight_Controller_Plugins_ViewRenderer_Bootstrap */
    public function render()
    {
        $template = $this->Action()->View()->Template();

        return $this->renderTemplate($template);
    }

    /** * Checks if the template should be rendered. * * @return bool */
    public function shouldRender()
    {
        return $this->Front() !== null
            && !$this->Front()->getParam('noViewRenderer')
            
Home | Imprint | This part of the site doesn't use cookies.