0

all I am trying to override list.phtml to customize product listing on every product listing pages. I tried this way. I have app/code/<Vendor>_<Module>/view/frontend/layout/catalog_category_view.xml file and copy list.phtml into my app/code/<Vendor>_<Module>/view/frontend/templates/product/list.phtml

But I see no changes to listing even after I run all the upgrade, cache, compile, deploy commands.

catalog_category_view.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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">Vendor_Module::product/list.phtml</argument>
        </action>
    </referenceBlock>
</body>

  • Instead of default list.phtml you want to show your custom list.phtml ? – aravind Sep 14 at 6:40
  • @aravind Yes!. i need to customize the cart button. so i need to override – Sanjun Dev Sep 14 at 6:51
1

Your xml file is invalid try below xml with layout attribute

<?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">Vendor_Module::product/list.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>
  • Still i am not able to see any changes :( . I am looking the changes in home page product listing section, is that exact place where these changes wil reflect? – Sanjun Dev Sep 14 at 7:23
  • How did you displayed products in home page? – Ranganathan Sep 14 at 7:25
  • It all automatically came by magento setup – Sanjun Dev Sep 14 at 7:27
  • catalog_category_view.xml for only category page... In home page product listing section might be widget i think...please find how they implemented – Ranganathan Sep 14 at 7:28
  • 1
    Or you can see the exact phtml file path by enabling Stores->Configuration->Advanced->Developer->Debug->Enable Template Path Hints for Storefront – Ranganathan Sep 14 at 7:30
1

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">
    <body>
            <!-- for magento catalog list overrider -->
            <referenceBlock name="category.products.list" template="Vendor_Modulename::product/list.phtml" />          
    </body>
</page>
1

You can override list.phtml with your module by following below code in module's catalog_category_view.xml file.

<?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/list.phtml"/>
           </referenceContainer>
    </body>
</page>

Also, if you want to customize the custom module product listing template, then you need to define their block class and your custom template for the same.

  • should i really use category in Module_NameSpace_ModuleName::category/list.phtml ? – Sanjun Dev Sep 14 at 7:24
  • its not compulsory, you can use your folder structure where the list.phtml.is placed in your module – Sumit Sep 14 at 7:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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