I have installed modules on Magento 2. I don't want to touch the module file. Is it possible to override that third-party module's template file from my Custom Module?
2 Answers
Use sequence in your module.xml
in order to load phtml file from your custom module
app/code/Custom/Module/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="Custom_Module" setup_version="1.0.0">
<sequence>
<module name="Thirdparty_Module"/>
</sequence>
</module>
</config>
app/code/Custom/Module/view/frontend/layout/thirdparty_module_action.xml
<referenceBlock name="third_party_block_name">
<action method="setTemplate">
<argument name="template" xsi:type="string">Custom_Module::thirdparty_template.phtml</argument>
</action>
</referenceBlock>
You can override custom module's template by overriding it in your theme as follows :
Copy it in your theme under the path app/design/frontend/Anshu/mytheme/Custom_Mymodule/templates/<path_to_template_file>
Anshu : Your theme namespace
mytheme : Your theme name
Custom_Mymodule : Your module's name
and make required modifications.
I hope this will help you.