I'm trying to override the list product page. My objective is add certain information on each product above the add to cart button for example.

I already did with the single page product, just overrided catalog_product_view.xml and added my block where I wanted.

But with list product I'm watching the catalog_category_view.xml and I really don't know how to it.

<block class="Magento\Catalog\Block\Product\ListProduct" name="category.products.list" as="product_list" template="Magento_Catalog::product/list.phtml">

product/list.phtml This template is doing all the work. So I only think to copy this template on my vendor's module and write my stuff where I want.

Is this the propper way? Can't I only write my block and indicate magento to use it? I don't like to copy all this 'core' template and write inside modifying it


2 Answers 2


you can rewrite the block

Step # 1 – Create a di.xml file in a folder FME/Test/etc

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
        <preference for="Magento\Catalog\Block\Product\ListProduct" type="FME\Test\Block\Rewrite\Product\ListProduct" />

Step # 2 - The next step to overriding Magento2 block is to create a ListProduct.php Block file in the folder FME/Test/Block/Rewrite/Product

    * Rewrite Product ListProduct Block
    * @category    FME
    * @package     FME_Test
    * @author      Fme Extensions Development Company

    namespace FME\Test\Block\Rewrite\Product;
    class ListProduct extends \Magento\Catalog\Block\Product\ListProduct
            public function __construct()
                    echo "you can do this in block"; die();


override phtml 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>


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


  • Following this solution, I encounter that I have to do all the work in the function: getProductDetailsHtml adding my stuff and I don't have so much control. How can I add my custom template in this case?
    – Marc Pont
    Dec 5, 2016 at 10:45
  • @slayerbleast doing module or theme? Dec 5, 2016 at 10:53
  • for module, on app/code/...
    – Marc Pont
    Dec 5, 2016 at 10:56
  • @slayerbleast i added the example for that too... Dec 5, 2016 at 11:00

You have to just write below xml code in your module file, In your module layout file,

app/code/Vendor/Modulename/view/frontend/layout/catalog_category_view.xml File,

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
            <!-- for magento catalog list overrider -->
            <referenceBlock name="category.products.list" template="Vendor_Modulename::product/list.phtml" />          
  • You can override using above method, please let me know if you have any issue Dec 5, 2016 at 11:00
  • Unable to over-ride class using this way. Sep 20, 2019 at 2:24

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