Search code examples
navigationzend-framework2twigpartial

How to use ZF2 navigation twig partial


I have layout.twig file with this line:

{{ navigation('navigation').menu().setUlClass("nav navbar-nav").setPartial(['partials/navigation.twig', 'Application'])|raw }}

inside of the navigation.twig I have these lines:

{{ ulClass }}
<?php echo "test"; die();?>

Unfortunately I see this as result:

{{ ulClass }}
test

Which means that twig file was parsed by default PHP render. How should I fix it? Please note layout.twig works just fine. Thanks.


Solution

  • The answer is to override invokables in the helper_manager section:

        'helper_manager' => array(
            'configs' => array(
                'Zend\Navigation\View\HelperConfig'
            ),
            'invokables' => array(
                "partial" => 'Zend\View\Helper\Partial',
                "paginationControl" => 'Zend\View\Helper\PaginationControl',
            )
        )
    

    After that partials are being parsed as twig files, not php.