0

I want to Override List.phtml and for that I'm using this Layout

Vender/Module/view/frontend/layout/catalog_category_view.xml

    <?xml version="1.0"?>
<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"> 
             <block class="Magento\Catalog\Block\Product\ListProduct" name="category.products.list" as="product_list" template="Vender_Module::product/list.phtml"/>
        </referenceContainer>
    </body>
</page>

I also create the custom list.phtml and ListProduct.php in my Module but after that still my module is not running my list.phtml its running its own list.phtml. What is the problem and how can I solve that Thanks in advance.

3 Answers 3

1

Currently, the code is adding a new block in the content area not overriding any phtml file.

Replace the code with the following code.

<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">Vender_Module::product/list.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

Reference

1
  • 1
    setTemplate is a deprecated method. Should avoid to use it.
    – Sohel Rana
    Commented Feb 6, 2019 at 7:53
1

Replace the code with the following code

app/code/Vendor/Module/view/frontend/layout/catalog_category_view.xml

Using New method

<?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">
            <arguments>
                <argument name="template" xsi:type="string">Vender_Module::product/list.phtml</argument>
            </arguments>
        </referenceBlock>
    </body>
</page>
0

<?xml version="1.0"?>
<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" template="Vender_Module::product/list.phtml"/>
    </body>
</page>

Clear cache

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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