As I dig deeper in Magento 2, I noticed that there are layout and page_layout file? What are the differences between the two?
Magento 2 – Difference Between Layout and Page Layout
magento2
Related Solutions
basically containers are the equivalent of the core/text_list
blocks in magento 1.
"philosophically" they work the same, the only difference is that containers
are predefined blocks that only support other child blocks.
Some examples are content
, after.body.start
, header-wrapper
.
You can see all defined containers for example in the Magento/Theme/view/base/page_layout/*
.
Here is an example from empty.xml
.
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_layout.xsd">
<container name="root">
<container name="after.body.start" as="after.body.start" before="-" label="Page Top"/>
<container name="page.wrapper" as="page_wrapper" htmlTag="div" htmlClass="page-wrapper">
<container name="global.notices" as="global_notices" before="-"/>
<container name="main.content" htmlTag="main" htmlId="maincontent" htmlClass="page-main">
<container name="columns.top" label="Before Main Columns"/>
<container name="columns" htmlTag="div" htmlClass="columns">
<container name="main" label="Main Content Container" htmlTag="div" htmlClass="column main"/>
</container>
</container>
<container name="page.bottom" as="page_bottom" label="Before Page Footer Container" after="main.content" htmlTag="div" htmlClass="page-bottom"/>
<container name="before.body.end" as="before_body_end" after="-" label="Page Bottom"/>
</container>
</container>
</layout>
basically what's defined as <container name="..." />
can be accessed by referenceContainer
. what's declared as <block .... />
can be referenced by referenceBlock
These matters due to a different XSD configurations. The
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
declaration says that we want to use layout with XSD definition provided in the
lib/internal/Magento/Framework/View/Layout/etc/layout_generic.xsd
In the layout_generic.xsd
file it provides definition for layout
node with genericLayout
element type.
<xs:complexType name="genericLayout">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element ref="referenceContainer" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="container" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="block" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="referenceBlock" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="update" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="move" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="uiComponent" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
Having that, the layout file has been validated by the XSD when xml is loaded. In addition to this it highlights all possible nodes and node attributes in the layout.xml file.
Same with page_configuration.xsd
definition for <page />
node. This XSD describes nodes which can be used to describe page.
Hope it helps.
Best Answer
Well if i put this in simple words than
page_layout represents the full page, i mean you can declare your own full page without inheriting any master or root or other empty layout. (only use, if you want to completely customize your own full page.)
layout represents the part of the page (mostly the html content). You can use this when you want your page to inherit the common contents from the root layout like header, footer etc etc.