3

I have installed one custom module using composer as usually that module was installed in vendor directory is there any way to override phtml file in the same module like name but on app/code

module install path -

vendor/vendorname/module/view/frontend/templates/product/view/addtocart.phtml

App path -

app/code/Vendorname/Module/view/frontend/templates/product/view/addtocart.phtml

Is there is any best possible way to override that and use the custom template file that resides in the app/code with the same vendor module ? just like we override the module file in the custom theme.

2 Answers 2

2

How to override with XML

Using layout xml

<referenceBlock name="block-name">
    <action method="setTemplate">
        <argument name="template" xsi:type="string">MyCustom_Module::path/to/my/file.phtml </argument>
    </action>
</referenceBlock>

How to override with PLUGIN

Declare your plugin either in etc/di.xml or etc/frontend/di.xml

namespace My\Module\Plugin;

class Block
{
    public function beforeToHtml(\Other\Module\Block $block)
    {
        $block->setTemplate('My_Module::path/to/my/file.phtml');
    }
}
0

You will require to override phtml file in design in your theme

app/design/Vendorname/themename/modulename/templates/product/view/addtocart.phtml

e.g for overrdie Magento paypal template file.

app/design/Vendorname/themename/Magento_Payapl/templates/yourphtml file path.

another example for third-party module installed by the composer is Magefan_Blog module

app/design/Vendorname/themename/Magefan_blog/templates/yourphtml file path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.