Layout file types
What's in this topic
For a particular page, its layout is defined by two major layout components: page layout file and page configuration file.
A page layout file defines the page wireframe, for example, one-column layout. Technically page layout is an .xml file defining the structure inside the <body>
section of the HTML page markup. Page layouts feature only containers.
All page layouts used for page rendering should be declared in the page layout declaration file.
Page configuration is also an .xml file. It defines the detailed structure (page header, footer, etc.), contents and page meta information, including the page layout used. Page configuration features both main elements, blocks of particular classes and containers.
We also distinguish the third type of layout files, generic layouts. They are .xml files which define the contents and detailed structure inside the <body>
section of the HTML page markup. These files are used for pages returned by AJAX requests, emails, HTML snippets and so on.
This article gives a comprehensive description of each layout file type.
Page layout
Page layout declares the wireframe of a page inside the <body>
section, for example one-column layout or two-column layout.
Allowed layout instructions:
Sample page layout:
<Magento_Theme_module_dir>/view/frontend/page_layout/2columns-left.xml
Page layout files conventional location
Conventionally page layouts must be located as follows:
- Module page layouts:
<module_dir>/view/frontend/page_layout
- Theme page layouts:
<theme_dir>/<Namespace>_<Module>/page_layout
Page layouts declaration
To be able to use a layout for actual page rendering, you need to declare it in layouts.xml
.
Conventionally layout declaration file can be located in one of the following locations:
- Module layout declarations:
<module_dir>/view/frontend/layouts.xml
- Theme layout declaration:
<theme_dir>/<Namespace>_<Module>/layouts.xml
Declare a layout file using the <layout></layout>
instruction, for which specify the following:
<layout id="layout_file_name">
. For example, the2columns-left.xml
page layout is declared like following:<layout id = "2columns-left"/>
<label translate="true|false">{Label_used_in_Admin}</label>
Sample page layout declaration file:
<Magento_Theme_module_dir>/view/frontend/layouts.xml
Page configuration
The page configuration adds content to the wireframe defined in a page layout file. A page configuration also contains page meta-information, and contents of the <head>
section.
Page configuration file conventional location
Conventionally page configuration files must be located as follows:
- Module page configurations:
<module_dir>/view/frontend/layout
- Theme page configurations:
<theme_dir>/<Namespace>_<Module>/layout
Page configuration structure and allowed layout instructions
The following table describes the instructions specific for page configuration files. For the descriptions of common layout instructions see the Layout instructions article.
Element | Attributes | Parent of | Description |
---|---|---|---|
<page></page>
|
|
|
Mandatory root element. |
<html></html> |
none |
|
Mandatory element. |
<head></head> |
none |
|
|
<body></body> |
none |
|
|
<attribute> |
|
Specified for
|
|
|
none | none | Page title |
|
|
none | |
|
|
none | |
<css>
|
|
none | |
|
|
none |
Generic layout
Generic layouts define the contents and detailed structure inside the <body>
section of the HTML page markup.
Generic layout file conventional location
Conventionally generic layout files must be located as follows:
- Module generic layouts:
<module_dir>/view/frontend/layout
- Theme generic layouts:
<theme_dir>/<Namespace>_<Module>/layout
Generic layout structure and allowed layout instructions
The following table describes the instructions specific for generic layout files. For the descriptions of common layout instructions see the Layout instructions article.
Element | Attributes | Parent of | Description |
---|---|---|---|
<layout></layout>
|
|
|
Mandatory root element. |
<update>
|
|
none | |
<container> |
|
|
Mandatory element |
Sample generic layout: