cancel
Showing results for 
Search instead for 
Did you mean: 

how to override product list.phtml file in magento ?

SOLVED
   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

how to override product list.phtml file in magento ?

 

Magento Version  : 2.2.4

 

As per client requirement, I need to override product listing page into my custom module so please suggest me how can i achieve this ?

 

2 ACCEPTED SOLUTIONS

Accepted Solutions

Re: how to override product list.phtml file in magento ?

Hello @yagnik_solanki,

 

You have to override below xml code in your module. 

 

app/code/VendorName/Modulename/view/frontend/layout/catalog_category_view.xml

 

<?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">
    <body>
        <referenceBlock name="category.products.list" template="Vendor_Modulename::product/list.phtml" />
    </body>
</page>

--
If you've found one of my answers useful, please give Kudos or Accept as Solution

 

View solution in original post

Re: how to override product list.phtml file in magento ?

9 REPLIES 9

Re: how to override product list.phtml file in magento ?

Hi @yagnik_solanki

 

Yes , you can override product listing page in your custom module !

 

You can refer this link for the same - https://magento.stackexchange.com/questions/148832/how-to-override-product-list-page

 

You will get complete step by step instruction on the given link !

if issue solved,Click Kudos & Accept as Solution

Re: how to override product list.phtml file in magento ?

Hello,

 

 

you can create catalog_category_view.xml into your module 

 

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body> 
        <referenceContainer name="content"> 
             <referenceBlock name="category.products" template="Module_NameSpace_ModuleName::category/products.phtml"
           </referenceContainer >
    </body>
</page>

Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: how to override product list.phtml file in magento ?

Hello @yagnik_solanki,

 

You have to override below xml code in your module. 

 

app/code/VendorName/Modulename/view/frontend/layout/catalog_category_view.xml

 

<?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">
    <body>
        <referenceBlock name="category.products.list" template="Vendor_Modulename::product/list.phtml" />
    </body>
</page>

--
If you've found one of my answers useful, please give Kudos or Accept as Solution

 

Re: how to override product list.phtml file in magento ?

Refer below blogs for override product list.phtml file,

How to override template-phtml files in magento-2

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: how to override product list.phtml file in magento ?

You can learn How to override a template phtml in Magento 2

 

I hope it will save your time.

Re: how to override product list.phtml file in magento ?

Thanks for suggestion

Re: how to override product list.phtml file in magento ?

<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="category.products.list" >
<action method="setTemplate">
<argument name="template" xsi:type="string">Vendorname_Modulename:Smiley Tongueroduct/list.phtml</argument>
</action>
</referenceBlock>
</body>
</page>

Re: how to override product list.phtml file in magento ?

Re: how to override product list.phtml file in magento ?

<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="category.products.list" >
<action method="setTemplate">
<argument name="template" xsi:type="string">Vendorname_Modulename:Smiley Tongueroduct/list.phtml</argument>
</action>
</referenceBlock>
</body>
</page>
Re: how to override product list.phtml file in magento ?

<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="category.products.list" >
<action method="setTemplate">
<argument name="template" xsi:type="string">Vendorname_Modulename:Smiley Tongueroduct/list.phtml</argument>
</action>
</referenceBlock>
</body>
</page>

 
 

Re: how to override product list.phtml file in magento ?

There are two way are doing it.

one from layout file and

 

<referenceBlock name="block-name" template="QaisarSatti_HelloWorld::path/to/my/file.phtml"/>

other is with plugin.

 

Declare your plugin either in etc/di.xml or etc/frontend/di.xml

<type name="Other\Module\Block">
    <plugin name="very-unique-name" type="QaisarSatti\HelloWorld\Plugin\Block" />
</type>

And then create a class QaisarSatti\HelloWorld\Plugin\Block with content like

<?php
namespace QaisarSatti\HelloWorld\Plugin;

class Block
{
    public function beforeToHtml(\Other\Module\Block $block)
    {
        $block->setTemplate('QaisarSatti_HelloWorld::path/to/my/file.phtml');
    }
}

 

Find helpful ? Consider Giving Kudos to this post.
Problem solved? Click Accept as Solution!"
Qaisar Satti