1

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

3

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";

?>
  • 1
    want to add in app/code – Rohan Hapani Jul 3 '17 at 6:17
  • @RohanHapani. See my updated answer :) – Prince Patel Jul 3 '17 at 6:22
  • Your always Welcome :) Happy Coding...! – Prince Patel Jul 3 '17 at 6:26
  • @RohanHapani, Accept answer for help other developers to find their solutions – Prince Patel Jul 3 '17 at 6:46
  • @PrincePatel, I need to add the same in custom module, what changes are required load the template in category list page? – jafar pinjar Dec 31 '18 at 7:59
2

Please try the below code.

<?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 after="product.info.price" class="Vendor/Module/Block/Module" name="extra" template="Vendor_Module::extra.phtml" />        
        </referenceContainer>
    </body>
</page>
  • please accept my answer – Jjo Jul 3 '17 at 6:25
  • Hi @Jjo the above file calling at the end of list section not after the price – shivashankar m Apr 3 '19 at 12:49
0

Add the below code in calatog_category_view.xml and replace the block name and template name with your custom block and template name

<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\Category\View" name="category.products" template="Magento_Catalog::category/products.phtml">
                <block class="Magento\Catalog\Block\Product\ListProduct" name="category.products.list" as="product_list" template="Magento_Catalog::product/list.phtml">
                    <block class="Magento\Catalog\Block\Product\ProductList\Item\Container" name="category.product.addto" as="addto">

                        <block as="product_list_blockname"  
                            class="<vendor>\<module>\Block\Product\<ClassName>"
                            name="product.list.<ClassName>" 
                            template="<template path>"/>

                    </block>
                </block>
            </block>
        </referenceContainer>
    </body>
</page>

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.