Magento2 – How to Override 3rd Party Module Layout File in Custom Theme

dependencymagento2moduleoverrides

We have a custom theme with some layout / template overrides

Now we have installed a 3rd party module, which is overriding one of layout files in our custom theme. So, only module's override is being loaded

I suppose, we can deal with this, by defining that concrete layout override in a custom module (instead of the custom theme approach), and then define the module dependencies to load both layout overrides

Or is there a way to do that without the need of declaring a new module?

UPDATE

About RishabhRkRai answer…

Let's say our custom theme is placed in folder app/design/frontend/Sinapsis/projectname

We had this layout override there:

app/design/frontend/Sinapsis/projectname/Magento_Multishipping/layout/multishipping_checkout_billing.xml

Now, we've installed a module which overrides that same layout file. The concrete module name is Df_Checkout, and problem is our layout override stopped working

I've tried, following the answer, moving our override to

app/design/frontend/Sinapsis/projectname/Df_Checkout/layout/multishipping_checkout_billing.xml

but only module's layout keeps loading

Best Answer

In your custom theme, follow this to override the layout file

app/design/frontend/Theme_Vendor/Theme_Name/ThirdPartyVendor_ModuleName/layout/file_to_override.xml

After doing this, remove the static files and flush the cache

  1. rm -rf pub/static/*
  2. php bin/magento setup:static-content:deploy
  3. php bin/magento cache:flush

There is an alternate way, which may works for you. You just need to create an custom module and inside module.xml add the dependency like

    <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_Modulename" setup_version="2.1.7">
        <sequence>
            <module name="ThirdParty_ModuleName"/>
        </sequence>
    </module>
</config>

Now you have to override the xml file as

app/code/Vendor/Module_Name/view/Scope/layout/file_to_override.xml

Scope can be either frontend or adminhtml (for backend)

Related Topic