Menu Close
    Searching for an experienced Magento 2 Development Company ?

    How to override phtml file in 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

    <h1>Shopping Cart</h1>
    //write your stuff here
    . . .
    Discuss on Helpdesk

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    5 comments

  • kaushik kumar roy
    But this technique is over riding the template, the products are not displaying. How to over ride the Shopping cart page to add any button or text along with cart products ?.
    • Webkul Support

      Hello,
      You can check our bloghttps://webkul.com/blog/add-product-information-checkout-cart-in-magento2/
      in this how to add an additional information on checkout page item in described.

      Hope this will help you.

      Thank you.

      Bulbul AgarwalSoftware engineer (Magento)

      Webkul Software Pvt. Ltd. Contact : India (+91)-9650486699 USA (+1)-9143531684

      A 67 Sector 63 ,
      Noida-201301 (U.P.)
      India

      http://webkul.com

      This email and any files transmitted with it are confidential and contain privileged or copyright information. If you are not the intended recipient you must not disseminate, copy, distribute, or use this email or the information contained in it for any purpose other than to notify us. If you have received this message in error, please notify the sender immediately, and delete this email from your system.

  • Maha
    how to override module-customer/view/frontend/templates/widget/name.phtml
    • Webkul Support

      Hello,
      To override this template file, either you have to override the block, or you can create a plugin for the function, in which this block is called.

      Thank you.

  • rajhees
    I want to override register.phtml in magento2 how to do please?
  • Back to Top