Skip to content

Commit

Permalink
Merge pull request #7682 from cakephp/layout-extension
Browse files Browse the repository at this point in the history
Add an example for layout extensions
  • Loading branch information
markstory authored Aug 20, 2023
2 parents fe7a457 + 0366c43 commit 7a88c14
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions en/views.rst
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,23 @@ as the ``content`` block.
You should avoid using ``content`` as a block name in your application.
CakePHP uses this for uncaptured content in extended views.

You can get the list of all populated blocks using the ``blocks()`` method::
Extending Layouts
=================

Just like views, layouts can also be extended. Like views, you use ``extend()``
to extend layouts. Layout extensions can update or replace blocks, and update or
replace the content rendered by the child layout. For example if we wanted to
wrap a block with additional markup you could do::

// Our layout extends the application layout.
$this->extend('application');
$this->prepend('content', '<main class="nosidebar">');
$this->append('content', '</main>');

// Output more markup.

$list = $this->blocks();
// Remember to echo the contents of the previous layout.
echo $this->fetch('content');

.. _view-blocks:

Expand Down

0 comments on commit 7a88c14

Please sign in to comment.