If you need to override ONLY some template just use <referenceBlock> in your module layout file. For example, you need to overwrite next template
ORIGINAL TEMPLATE:
vendor/magento/module-customer/view/frontend/templates/form/edit.phtml
ORIGINAL LAYOUT:
vendor/magento/module-customer/view/frontend/layout/customer_account_edit.xml
ORIGINAL BLOCK in LAYOUT (where this template assigned to):
<block class="Magento\Customer\Block\Form\Edit" name="customer_edit" template="Magento_Customer::form/edit.phtml" cacheable="false">
<container name="form.additional.info" as="form_additional_info"/>
</block>
OVERRIDING PROCESS
- Create your own layout with the same handle
app/code/YourVendor/YourModule/view/frontend/layout/customer_account_edit.xml
- Put there code with <referenceBlock> tag and original "name" of this block where you can redefine path to your custom template (be carefull with paths, they starts from view/frontend/templates in declared module) like
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="customer_edit"
template="YourVendor_YourModule::form/edit.phtml"/>
</body>
- Create your custom template in your module with a mentioned name:
app/code/YourVendor/YourModule/view/frontend/templates/form/edit.phtml
That's it!