2

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.

2

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

  • Hi @Pawan Thanks for reply, that means if we need to add custom phtml file we can Override a layout and as per MagentoDocs we can't change handle, block name or alias? I think Extending a layout is better way instead of Override a layout. what you say ? – hweb87 Aug 29 '18 at 6:41
  • When we should use override layout files ? – hweb87 Aug 29 '18 at 7:03
  • Hello @hweb87, Extending layout work in most of the cases like adding a phtml. For example we need to add an extra field in registration form. But many times extending not work then we need to override layout. For example if we need to add header and footer at checkout pages. i tried with with extending but that not work but override work for adding header at checkout. – Pawan Aug 30 '18 at 2:50
  • in the official document they said "Not all layout customizations can be performed by extending", But not provide an example. – Pawan Aug 30 '18 at 2:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.