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.

  • can you please share with me your phtml file path and where you want to override ? – hweb87 Apr 30 '18 at 5:32
  • @hweb87 I just edited the question. – Divyesh Apr 30 '18 at 5:42
  • Do you want to override adminhtml file ? /vendor/magento/module-sales/view/adminhtml/templates/order/view/info.phtml – hweb87 Apr 30 '18 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 Apr 30 '18 at 5:49
  • May be this will help to you magento.stackexchange.com/questions/223916/… – hweb87 Apr 30 '18 at 5:52
0

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

To call your phtml file at place of core(magento’s) file, you need to follow:

Firstly, create a 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>
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>

  • 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 May 1 '18 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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