ZF-8013: Nested layouts, in Zend_Layout

Description

Nested layouts in Zend_Layout would be really useful. Sometimes you have a page that's split in multiple larger segments, where you would need several layouts, to get it right.

I've recently needed it in a project, and i didn't come up with a nice solution using helpers/actions etc.

It's also useful if you just want your current view wrapped in some plain HTML.

I've looked elsewhere, and Symfony templating has this feature, implemented really well, and simple. http://components.symfony-project.org/templating/… (Under "Inheritance"). I believe django has this as well, with their templating solution, and ZF would benefit from it as well.

Usage is something like:



<?php $this->layout()->extend('wrapper') ?>

This is my view wrapped by a layout.

<?= $this->layout()->content ?>

Expected result


This is my view wrapped by a layout.

I've attached a really simple patch that implements the functionality. It's basically just the same strategy as the symfony templating solution uses, and in my view it fits quite nicely with Zend_Layout, and actually i'm a bit surprised this hasn't been thought of before. Unless i'm missing some proper way of doing this.

My patch - (Basically a port of symfonys strategy) can be found here: http://gist.github.com/201465

I couldn't find anything in the license that prevents this from going into ZF but maybe i'm wrong. According to the templating web-page, it's released under the MIT license.

Raw version is attached.

Comments

Patch to provide nested layouts for Zend_Layout

This issue might also enable a good solution to the problem with Dojo widgets being created after the echo $this->dojo();, see Stackoverflow zend-dojo-form-in-a-layout and Stackoverflow zend-dojo-form-not-rendering-in-layout that have problems when they can't nest a layout containing all the Dojo code into the main layout. I've also asked the docs to be clarify on this point. Adding this functionality would probably be the most elegant way for getting Dojo widgets into the layout.