Reading list Switch to dark mode

    How to Override phtml file in Magento 2

    Updated 23 February 2024

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

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

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

    create checkout_cart_index.xml inside :

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

    Searching for an experienced
    Magento 2 Company ?
    Find out More
    <?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 the 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 the location:

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

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

    That is all for this dev doc article on how to Override phtml File in Magento 2. For more queries, you can reach out to our team via a support ticket.

    . . .

    Leave a Comment

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


    5 comments

  • kaushik kumar roy
    • Webkul Support
  • Maha
    • Webkul Support
  • rajhees
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home