How to extend layout in Magento 2 Programmatically

Follow the following steps to extend the layout in Magento 2

  • Create theme extending file
  • Processing extending layouts

Create theme extending file

Add extending page configuration or generic layout file

<theme_dir>
|__/<Namespace>_<Module>
|__/layout
|--<layout1>.xml
|--<layout2>.xml

For example, to customise/extend the layout.

<Magento_Catalog_module_dir>/view/frontend/layout/catalog_product_view.xml

Add extending page layout file

For extending the page layout, follow this path.

<theme_dir>
|__/<Namespace>_<Module>
|__/page_layout
|--<layout1>.xml
|--<layout2>.xml

Processing extending layouts

<layouts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<handle id="checkout_cart_index" label="Shopping Cart" type="page" parent="default">
<!-- Layout instructions from checkout_cart_index.xml -->
</handle>
<handle id="checkout_onepage_index" label="One Page Checkout" type="page" parent="default">
<!-- Layout instructions from checkout_onepage_index.xml -->
</handle>
<!-- ... -->
</layouts>

 

If you are looking for Magento Developers, visit Magento Developer Agency.