|
I've just updated my code to the latest master branch for zf2. I have
created a module in the module directory named Admin. In my config file I have: 'view_manager' => array( 'template_path_stack' => array( 'admin' => __DIR__ . '/../view', ), ), and my view scripts render fine. However, when I try to change the layout template for the Admin module by adding: 'view_manager' => array( 'template_map' => array( 'layout/layout' => __DIR__ . '/../view/layout/layout.phtml', ), 'template_path_stack' => array( 'admin' => __DIR__ . '/../view', ), ), Now my admin layout becomes my default template for all modules both Application and Admin. The Admin config appears to overwrite the Application ('layout/layout') value. I can change the layout in my admin controller but only if the template filename is different.: $this->layout()->setTemplate('layout/admin') works, though $this->layout()->setTemplate('layout/layout'); displays the layout from my Application module. I'm assuming this is a bug? Any help is appreciated. regards, ron -- ======================= Ron Dyck Webbtech [hidden email] www.webbtech.net twitter.com/pulpfree ======================== |
|
Hi Ron,
On Mon, May 21, 2012 at 10:35 AM, Ron Dyck <[hidden email]> wrote: > I've just updated my code to the latest master branch for zf2. I have > created a module in the module directory named Admin. In my config > file I have: > 'view_manager' => array( > 'template_path_stack' => array( > 'admin' => __DIR__ . '/../view', > ), > ), > and my view scripts render fine. > However, when I try to change the layout template for the Admin module > by adding: > 'view_manager' => array( > 'template_map' => array( > 'layout/layout' => __DIR__ . '/../view/layout/layout.phtml', > ), > 'template_path_stack' => array( > 'admin' => __DIR__ . '/../view', > ), > ), > > Now my admin layout becomes my default template for all modules both > Application and Admin. The Admin config appears to overwrite the > Application ('layout/layout') value. > I can change the layout in my admin controller but only if the > template filename is different.: > $this->layout()->setTemplate('layout/admin') works, though > $this->layout()->setTemplate('layout/layout'); displays the layout > from my Application module. > > I'm assuming this is a bug? Any help is appreciated. No, this is not a bug. It's the intended behavior. The template path stack is not "module aware" at all (and it shouldn't be). You made a false assumption about what the 'admin' key is about in the template path stack. That was actually because we used to be using array_replace_recursive to merge the module configs, so if you did not provide a key for each path in the array, it would result in multiple numeric-indexed arrays which would override each other. You actually no longer need to have such a key, and your config can simply look like: 'view_manager' => array( 'template_path_stack' => array( __DIR__ . '/../view', ), ), That said, I actually wrote a blog post on the subject of "module-specific" layouts which should answer your underlying question: http://blog.evan.pro/module-specific-layouts-in-zend-framework-2 -- Evan Coury |
|
This post has NOT been accepted by the mailing list yet.
Ah, ic. Thanks! Your article resolved my issue.
Thanks again. ron On Mon, May 21, 2012 at 4:47 PM, EvanDotPro [via Zend Framework Community] <[hidden email]> wrote: > Hi Ron, > > On Mon, May 21, 2012 at 10:35 AM, Ron Dyck <[hidden email]> wrote: > >> I've just updated my code to the latest master branch for zf2. I have >> created a module in the module directory named Admin. In my config >> file I have: >> 'view_manager' => array( >> 'template_path_stack' => array( >> 'admin' => __DIR__ . '/../view', >> ), >> ), >> and my view scripts render fine. >> However, when I try to change the layout template for the Admin module >> by adding: >> 'view_manager' => array( >> 'template_map' => array( >> 'layout/layout' => __DIR__ . '/../view/layout/layout.phtml', >> ), >> 'template_path_stack' => array( >> 'admin' => __DIR__ . '/../view', >> ), >> ), >> >> Now my admin layout becomes my default template for all modules both >> Application and Admin. The Admin config appears to overwrite the >> Application ('layout/layout') value. >> I can change the layout in my admin controller but only if the >> template filename is different.: >> $this->layout()->setTemplate('layout/admin') works, though >> $this->layout()->setTemplate('layout/layout'); displays the layout >> from my Application module. >> >> I'm assuming this is a bug? Any help is appreciated. > > No, this is not a bug. It's the intended behavior. The template path > stack is not "module aware" at all (and it shouldn't be). You made a > false assumption about what the 'admin' key is about in the template > path stack. That was actually because we used to be using > array_replace_recursive to merge the module configs, so if you did not > provide a key for each path in the array, it would result in multiple > numeric-indexed arrays which would override each other. You actually > no longer need to have such a key, and your config can simply look > like: > > 'view_manager' => array( > 'template_path_stack' => array( > __DIR__ . '/../view', > ), > ), > > That said, I actually wrote a blog post on the subject of > "module-specific" layouts which should answer your underlying > question: http://blog.evan.pro/module-specific-layouts-in-zend-framework-2 > > -- > Evan Coury > > > ________________________________ > If you reply to this email, your message will be added to the discussion > below: > http://zend-framework-community.634137.n4.nabble.com/Bug-with-Layout-template-in-zf2-tp4648491p4648839.html > To start a new topic under ZF Contributor, email > [hidden email] > To unsubscribe from ZF Contributor, click here. > NAML -- ======================= Ron Dyck President Webbtech [hidden email] www.webbtech.net twitter.com/pulpfree ======================== |
|
This post has NOT been accepted by the mailing list yet.
In reply to this post by pulpfree
very good I also had this problem and solved thanks to this post.
|
| Powered by Nabble | Edit this page |
