phpzend-framework2zend-framework-modules

Configure ZF2 view_manager to load 2 separate templates maps


I need 2 different template maps in ZF2 , one for admin and oen for front-end, currently from what I can see ZF2 merges the 2 module.config.php files that are used in the 2 modules I configured, and causes the template map I need to set for the admin, to be loaded in front module also.

the /Application module.config.php

...
'view_manager' => array(
        'display_not_found_reason' => true,
        'display_exceptions'       => true,
        'doctype'                  => 'HTML5',
        'not_found_template'       => 'error/404',
        'exception_template'       => 'error/index',
        'template_map' => array(
            'layout/layout'           => __DIR__ . '/../view/layout/layout.phtml',
            'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
            'error/404'               => __DIR__ . '/../view/error/404.phtml',
            'error/index'             => __DIR__ . '/../view/error/index.phtml',
        ),
        'template_path_stack' => array(
            __DIR__ . '/../view',
        ),
...

the /admin module.config.php

...
'view_manager' => array(
        'template_path_stack' => array(
            'admin' => __DIR__ . '/../view',
        ),
        'template_map' => array(
            'layout/layout'           => __DIR__ . '/../view/layout/layout.phtml',
        ),
    ),
...

what should I modify so that i can load separate "view_manager" arrays for the 2 separate modules ?


Solution

  • It would be great if you can explain why you are trying to achieve this. As i can see you are trying to have a different layout for admin. Maybe you want to take a look at this module which can already do what you are trying https://github.com/zf-commons/zfcadmin. This module has a layut setup for the admin route.