2

I faced problem with overriding a phtml file in Magento 2.

I want this:-

(1) Core Module of phtml Override By Custom Module called - A

(2) Same phtml file of Module - A Override By Some Custom Module - B

Example:- Magento_Sales::order/view/info.phtml

This file override by Module-A And I want override Module - A info.phtml in my custom Module-B

Issue:- So that the issue will arise that Module - B cannot override that phtml file.

10
  • can you please share with me your phtml file path and where you want to override ? Commented Apr 30, 2018 at 5:32
  • @hweb87 I just edited the question.
    – Divyesh
    Commented Apr 30, 2018 at 5:42
  • Do you want to override adminhtml file ? /vendor/magento/module-sales/view/adminhtml/templates/order/view/info.phtml Commented Apr 30, 2018 at 5:44
  • yes, I want to override this file but this file already overrides Module-A, I want to override the same file with Module-B.
    – Divyesh
    Commented Apr 30, 2018 at 5:49
  • May be this will help to you magento.stackexchange.com/questions/223916/… Commented Apr 30, 2018 at 5:52

2 Answers 2

0

Make sure you have mentioned proper module sequence that is very important for overriding. You may check your module sequence is correct or not to view app/etc/config.php in this file all the modules listed enable/disable with sequence which one is going to load first. if your module B loading before A then phtml will not be override. For more details please refer Magento guide.
http://devdocs.magento.com/guides/v2.0/extension-dev-guide/build/module-load-order.html

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_ComponentB" setup_version="0.0.1">
    <sequence>
    <!-- Vendor_ComponentB is dependent on Vendor_ComponentA: -->
        <module name="Vendor_ComponentA" />
    </sequence>
</module>

1
  • you are right but this not a solution of my issue because this is merged layout, but this will not override phtml. I had already tried this.
    – Divyesh
    Commented May 1, 2018 at 8:35
0

This is an example of how to override the core .phtml file. You can refer to the below link for more information. https://webkul.com/blog/override-phtml-file-magento2/

To call your phtml file at the place of core(Magento's) file, you need to follow:

Firstly, create an xml file with the controller name, on which page you want to override.

For example: here we override checkout/cart/index controller page file.

create checkout_cart_index.xml inside :

app/code/Webkul/Hello/view/frontend/layout folder

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance dc" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<referenceBlock name="checkout.cart">
    <action method="setTemplate">
        <argument name="template" xsi:type="string">Webkul_Hello::cart.phtml</argument>
    </action>
</referenceBlock>
</page>

Here,

checkout.cart : is block name, whose template file you want to override.

Webkul_Hello::cart.phtml : is a template file of your module.

Now, create cart.phtml file at location:

app/code/Webkul/Hello/view/frontend/templates folder

//write your stuff here
<h1>Shopping Cart</h1>

Your Answer

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

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