Override a layout

Not all layout customizations can be performed by extending layouts. If the amount of customizations is large, you can use the overriding function for the needed layout file. This means that the new file that you place in the theme will be used instead of the parent theme layout file or base layout file.

In this article, page layouts, page configurations, and generic layouts are referred to as layout files, as the mechanism of overriding is similar for all of them.

Layout files with instructions that override the default or parent theme files are referred to as overriding layout files.

Examples of customizations that override layouts

Examples of customizations that involve overriding layouts:

data-variant=info
data-slots=text
Certain attributes, like htmlClass, htmlId, label attributes can be changed in extending layouts.

How to override a layout

This section discusses how to override:

Override base layouts

To add an overriding base layout file (to override a base layout provided by the module):

  1. Put a layout file with the same name in the following location:

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

These files override the following layouts:

For example, <theme_dir>/Magento_Checkout/layout/override/base/checkout_cart_index.xml will override Magento_Checkout/view/frontend/layout/checkout_cart_index.xml.

Override theme layouts

To add an overriding theme file (to override a parent theme layout):

  1. Put a layout file with the same name in the following location:
<theme_dir>
  |__/<Namespace_Module>
    |__/layout
      |__/override
         |__/theme
            |__/<Parent_Vendor>
               |__/<parent_theme>
                  |--<layout1>.xml
                  |--<layout2>.xml

These files override the following layouts:

For example, <theme_dir>/Magento_Checkout/layout/override/theme/Magento/luma/checkout_cart_index.xml will override app/design/frontend/Magento/luma/Magento_Checkout/layout/checkout_cart_index.xml.

data-variant=info
data-slots=text
To override page layout files, use the page_layout directory name instead of layout.

Customization mistakes

Although the layout overriding mechanism provides great customization flexibility, it's possible to use it to add logically irrelevant changes. We strongly recommend you not make the following changes: