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.
5 comments
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.
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.