Question

I'm trying to override Magento_Catalog list.phtml in magento 2.1.6 and it's not working. I have a theme working and others templates and layouts overrides are working correctly.

My custom list.phtml is here:

app\design\frontend\vendor\theme\Magento_Catalog\templates\product\list.phtml

If I remove "category.product.list" in my "catalog_category_view.xml" in

app\design\frontend\vendor\theme\Magento_Catalog\layout

with this funcion:

<referenceBlock name="category.products.list" remove="true" />

product grid disappears.

I've tried also to disable modules but it's not working.

I'm doing tests modifying list.phtml line 68 link class:

    <a class="product-item-link test"

And in my grid isn't showing this change.

Was it helpful?

Solution

Since when doing reference for removing it works , i m guessing that you are using the current active theme.

Make sure you are in developer mode and then I would try to clean pub/static and var/view_preprocessed and redeploy static content. If this doesn't work try and extend the layout. In app\design\frontend\vendor\theme\Magento_Catalog\layout\catalog_category_view.xml

......
<referenceContainer name="content">
        <block class="Magento\Catalog\Block\Category\View" name="category.products" template="Magento_Catalog::category/products.phtml">
            <block class="Vendor\Module\Block\Product\ListProduct" name="category.products.list" as="product_list" template="Magento_Catalog::product/list.phtml">
...... rest of file depending on what you are extending

I had to extend ListProduct.php for different reasons so i don't know if it works with default but this is working for me.

OTHER TIPS

To override a template you only need to move it into your theme, the XML you have written is removing the template so it will no longer be rendered.

Remove the line with remove="true" and clear cache and Magento should use your template.

if you remove block than you cant use same block for custom list file.

<referenceBlock name="category.products.list" remove="true" />

so you have to use this Layout with your custom block name and custom-list.phtml

    <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.custom" as="product_list" template="Magento_Catalog::product/custom-catalog-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" name="category.product.type.details.renderers.default" as="default"/>
                </block>
                <block class="Magento\Catalog\Block\Product\ProductList\Item\Container" name="category.product.addto" as="addto">
                    <block class="Magento\Catalog\Block\Product\ProductList\Item\AddTo\Compare"
                           name="category.product.addto.compare" as="compare"
                           template="Magento_Catalog::product/list/addto/compare.phtml"/>
                </block>
                <block class="Magento\Catalog\Block\Product\ProductList\Toolbar" name="product_list_toolbar" template="Magento_Catalog::product/list/toolbar.phtml">
                    <block class="Magento\Theme\Block\Html\Pager" name="product_list_toolbar_pager"/>
                </block>
                <action method="setToolbarBlockName">
                    <argument name="name" xsi:type="string">product_list_toolbar</argument>
                </action>
            </block>
        </block>
    </referenceContainer>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top