Skip to content

Latest commit

 

History

History
executable file
·
38 lines (34 loc) · 884 Bytes

TwigModel.md

File metadata and controls

executable file
·
38 lines (34 loc) · 884 Bytes

TwigModel

Zend Framework has interesting approach how to get correct renderer. By default flow developer has something like this in controllers

public function indexAction()
{
    // \Zend\View\Model\ViewModel
    return new ViewModel([
        'foo' => 'bar',
    ]);
}

In this case ZF will render template with PhpRenderer.

When developer would like to send JSON response, then we can change to

public function indexAction()
{
    // \Zend\View\Model\JsonModel
    return new JsonModel([
        'foo' => 'bar',
    ]);
}

Now, with this extension developer can use TwigModel to render Twig templates with TwigRenderer.

public function indexAction()
{
    // \ZendTwig\View\TwigModel
    return new TwigModel([
        'foo' => 'bar',
    ]);
}

NOTE: To have described behaviour, please, set 'force_twig_strategy' to false