View Blocks

It would be cool if there was a "getter" for View::blocks array.

Something like




function getBlock($id, $default = '')

{

    return isset($this->blocks[$id]) ? $this->blocks[$id] : $default;

}



so one can simply write


<?= $this->getBlock('top') ?> 

or


<?= $this->getBlock('top', 'this block has not been set yet, take this defaults') ?> 

and forget about it.

As for now, we have to check if corresponding index exists in array, otherwise a notice will be thrown.

Whats your use case for it?

Overriding layout parts from views.

For example: suppose I have an advertisement block that should be the same on almost every site page except some special pages.

So I need to override its content from views, just like I do with $this->title.

Maybe the blocks aren’t supposed to be used this way, but they seem to be the best replacement for “template inheritance” (as in Django and some other frameworks)