Zend framework 2 - Add a subview in layout?

1.1k views Asked by At

I have three layout views for render my web page (one for logged users, other for unlogged users and one for admin users). These layouts have the same footers section. This footer is very complex and I'd like centralizing changes to a single footer view.

How I can add a subview inside the layout view, such that the layout will have the following code for rendering the content returned by actionControler?

<?php echo $this->content; ?> 

And the following code, but this is always same template and isn't returned by the actionController:

<?php echo $this->footer; ?> 

Do I have to modify onBootstrap method?

1

There are 1 answers

1
DrBeza On

If the footer itself is simple you should be able to use the Zend\View\Helper\Partial helper to render a phtml file. To do this (inside your layout):

<?php echo $this->partial('view path'); ?>

If the footer requires some logic, it maybe best to look at creating a view helper.