How to Override phtml file in Magento 2
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
<?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.
Categories:
Magento2
Tags:
Magento2
View Comments (5)
Comment or Ask a Question
Quick Links