Magento2 Layout Overrides – Difference Between Extend a Layout and Override Layout

layoutmagento2overridesxml

In Magento2 currently, I override XML file using below way and make required changes.

app/design/frontend/Vendor/Theme/Magento_Catalog/layout/default.xml

But I have seen in Magento dev docs different way to override XML.

app/design/frontend/Vendor/Theme/Magento_Catalog/layout/override/theme/Magento/luma/default.xml

Can anyone explain what is the difference between Extend a layout and Override layout.

Best Answer

Extending Means create a layout file and just add your changes, Overriding need whole code to be present in the layout

Extending a layout:

Rather than copy extensive page layout or page configuration code and then modify what you want to change, in the Magento system, you only need to create an extending layout file that contains the changes you want.

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

Override a layout

Not all layout customizations can be performed by extending existing layouts. If the amount of customizations is large, you can use the overriding function for the needed layout file.

<theme_dir>
  |__/<Namespace_Module>
    |__/layout
      |__/override
         |__/base
           |--<layout1>.xml
           |--<layout2>.xml

You can find a detailed tutorial at Magento Official site at below link

Extend Layout Source

Override Layout Source

Related Topic