Magento2 - override 3rd party module layout file in custom theme
-
15-04-2021 - |
Question
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
Solution
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
- rm -rf pub/static/*
- php bin/magento setup:static-content:deploy
- 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)
OTHER TIPS
Please note that magento has 2 ways to customize layout.
Extend layout http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/layout-extend.html
Override layout http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/layout-override.html
Here are a few steps to make sure that your layout is extended correctly.
- move layout in your theme
app/design/frontend/Sinapsis/projectname/Df_Checkout/layout/multishipping_checkout_billing.xml
Check the layout and make sure that block names match.
Check the code in your Block. There are cases when the template was updated directly in the block code. In that way you need to extend the Block.
As per Magento documentation you need to put the layout file under "layout/override/base". Try this example ( tested on Magento ver. 2.3.5)
<theme_dir>/Smile_ElasticsuiteCatalog/layout/override/base/catalog_category_view_type_layered.xml
will override
vendor/smile/elasticsuite/src/module-elasticsuite-catalog/view/frontend/layout/catalog_category_view_type_layered.xml