Question

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>

Was it helpful?

Solution

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>

OTHER TIPS

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>

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top