I have a custom list.phtml
file in
app\design\frontend\BSS\ContactUs\Magento_Catalog\templates\product\list.phtml
And I want to override it on
\vendor\magento\module-catalog\view\frontend\templates\product\list.phtml
How to make it work?
For override list.phtml via custom module
Create view/frontend/layout/catalog_category_view.xml and put this 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">Magetest_Test::product/list.phtml</argument>
</action>
</referenceBlock>
</body>
</page>
Next create new file view/frontend/templates/product/list.phtml set your code.
Create a below file in mention path with below code.
app\design\frontend\BSS\ContactUs\Magento_Catalog\layout\catalog_category_view.xml
<?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">Magento_Catalog::product/list.phtml</argument>
</action>
</referenceBlock>
</body>
</page>
For override list.phtml
\vendor\magento\module-catalog\view\frontend\templates\product\list.phtml
Copy this file to your theme
app\design\frontend\BSS\ContactUs\Magento_Catalog\templates\product\list.phtml
And apply custimization as per your requirement
create block file and the file should extend ListProduct
.
<?php
namespace Frontname\Modulename\Block\Crosssell;
class Autocrosssell extends \Magento\Catalog\Block\Product\ListProduct
{
//your functions
}
?>
Create view/frontend/layout/checkout_cart_index.xml and put this code.
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<css src="Magento_Swatches::css/swatches.css"/>
</head>
<body>
<referenceContainer name="checkout.cart.items">
<block class="Frontname\Modulename\Block\Crosssell\Autocrosssell" name="custom.products.list" as="product_list" template="Frontname_Modulename::checkout/cart/list.phtml">
<!-- <container name="category.product.list.additional" as="additional" /> -->
<block class="Magento\Framework\View\Element\RendererList" name="category.product.type.details.renderers" as="details.renderers">
<block class="Magento\Framework\View\Element\Template" as="default"/>
</block>
<referenceBlock name="category.product.type.details.renderers">
<block class="Magento\Swatches\Block\Product\Renderer\Listing\Configurable" as="configurable" template="Magento_Swatches::product/listing/renderer.phtml" />
</referenceBlock>
</block>
</referenceContainer>
</body>
</page>
Try this
Content > design configuration
in your Magento from your Magento admin? if yes then try to refresh your cache & then see the changes