1

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.

  • Check if any module is overriding this phtml and taking preference over theme. – Sejal Shah Jun 1 '17 at 7:38
1

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.

  • Overriding block by XML it's working. But I changed: <block class="Vendor\Module\Block\Product\ListProduct" .... for: <block class="Magento\Catalog\Block\Product\ListProduct" because I don't have any module overriding ListProduct.php – Eduardo Pedrosa Jun 1 '17 at 7:39
0

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.

  • XML update it's a test. It's only for check the template overriding it's working. The problem is with list.phtm. – Eduardo Pedrosa Jun 1 '17 at 7:31
0

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>

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.