Load Custom Block in Category List Page in Magento2

category-listinglayoutmagento2

I am trying to add custom template file in category list page.

app/design/frontend/Vendor/Theme/Magento_Catalog/layout/catalog_category_view.xml

<referenceContainer name="content">
        <block class="Magento\Framework\View\Element\Template" name="custom.block" template="Magento_Catalog::product/myCustomFile.phtml" />
    </referenceContainer>

This is loading the template in list page.

But i need to load it from my custom module.

I used below code to implement it.

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

 <referenceContainer name="content">
    <block class="Magento\Framework\View\Element\Template" name="custom.block" template="Vendor_Module::product/myCustomFile.phtml" />
</referenceContainer>

This is not loading my template in category list page. After using layout update also.

Can anyone help me on this please

Best Answer

create catalog_category_view.xml in your layout folder

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" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <css src="Addify_ProductSold::css/sales_style.css"/>
    </head>
    <body>
        <referenceContainer name="content">
            <block class="Magento\Framework\View\Element\Template" name="custom.block" template="Vendor_Module::product/myCustomFile.phtml" before="-" />

        </referenceContainer>
    </body>
</page>
Related Topic