Magento2 Catalog Frontend – How to Add Custom phtml in Catalog View Page

catalogfrontendmagento2

I want to add some custom code in my catalog category view page. I don't want to override product/list.phml file . But just display my custom code in catagory view page.

How to add it?

enter image description here

Best Answer

Create catalog_category_view.xml

app/code/Vendor/Module/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>
        <referenceContainer name="content">
            <block class="Magento\Framework\View\Element\Template" name="custom.block" template="Vendor_Module::myCustomFile.phtml" />
        </referenceContainer>
    </body>
</page>

Now create myCustomFile.phtml and place your code

app/code/Vendor/Module/view/frontend/templates/myCustomFile.phtml

<?php

echo "This is my custom file for product list page";

?>