Magento Version : 2.2.4
As per client requirement, I need to override product listing page into my custom module so please suggest me how can i achieve this ?
Solved! Go to Solution.
Hello @yagnik_solanki,
You have to override below xml code in your module.
app/code/VendorName/Modulename/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> <referenceBlock name="category.products.list" template="Vendor_Modulename::product/list.phtml" /> </body> </page>
--
If you've found one of my answers useful, please give Kudos or Accept as Solution
Yes , you can override product listing page in your custom module !
You can refer this link for the same - https://magento.stackexchange.com/questions/148832/how-to-override-product-list-page
You will get complete step by step instruction on the given link !
Hello,
you can create catalog_category_view.xml into your module
<?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/products.phtml" </referenceContainer > </body> </page>
Hello @yagnik_solanki,
You have to override below xml code in your module.
app/code/VendorName/Modulename/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> <referenceBlock name="category.products.list" template="Vendor_Modulename::product/list.phtml" /> </body> </page>
--
If you've found one of my answers useful, please give Kudos or Accept as Solution
Refer below blogs for override product list.phtml file,
How to override template-phtml files in magento-2
Thanks for suggestion
<?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">Vendorname_Modulename:roduct/list.phtml</argument>
</action>
</referenceBlock>
</body>
</page>
Re: how to override product list.phtml file in magento ? <?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">Vendorname_Modulename:Smiley Tongueroduct/list.phtml</argument> </action> </referenceBlock> </body> </page>Re: how to override product list.phtml file in magento ?
<?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">Vendorname_Modulename:roduct/list.phtml</argument>
</action>
</referenceBlock>
</body>
</page>
There are two way are doing it.
one from layout file and
<referenceBlock name="block-name" template="QaisarSatti_HelloWorld::path/to/my/file.phtml"/>
other is with plugin.
Declare your plugin either in etc/di.xml or etc/frontend/di.xml
<type name="Other\Module\Block"> <plugin name="very-unique-name" type="QaisarSatti\HelloWorld\Plugin\Block" /> </type>
And then create a class QaisarSatti\HelloWorld\Plugin\Block with content like
<?php namespace QaisarSatti\HelloWorld\Plugin; class Block { public function beforeToHtml(\Other\Module\Block $block) { $block->setTemplate('QaisarSatti_HelloWorld::path/to/my/file.phtml'); } }