-
Notifications
You must be signed in to change notification settings - Fork 1
How It Works
When the render()
method is called, The system loads all the handles that need to be handled and then Layout files get read ($this->getLayout()->getUpdate()->load())
. The same method also compiles the layout ($this->generateXml())
which processes the layout directives.
Output is rendered when the system calls $this->renderLayout()
, which calls each of the blocks defined to output data e.g. output="toHtml"
in the definition, and merged their output into the response body.
####Rendering Process
Before rendering the page, all block elements defined in the layout are instantiated. Nested block elements define child blocks. If any block element defines an output attribute, then it is considered as an output block. Only the output blocks are rendered and added to the response. All other child blocks are rendered only if they are called by the parent block. Let’s see how this works.
The block root is defined as an output block. This block is defined in the default.xml file. With the particular value of the template attribute, this block defines the page template to be used when rendering it,
i.e:
- 1 column
- 2 columns with left sidebar
- 2 columns with right sidebar
- 3 columns
By default, the 3 columns template is assigned to the page. There are also other child blocks defined under root like head, header, breadcrumbs, left, right, content, footer etc. These child blocks are rendered in the root template file (3columns.blade.php) by calling something like this:
{!! $_this->getChildHtml('header') !!}
In any template, the child blocks can be rendered by calling the getChildHtml()
method as above and passing the child block name as the first argument. If the method is called without arguments, it will render all child blocks of the current block that are defined in the layout XML for that block.
Hence, Layout processes layout using a recursive rendering process. First the root block then its child blocks and then the child’s child blocks and so on.