Magento 2 – Custom Product List Template for Category Layout Update

categorylayout-updatemagento2product-listtemplate

I'm trying to apply an XML Layout Update to a small selection of categories to have a custom product listing design. All other categories need to remain as-is so I cannot simply globally change the product list template for all categories.

I have already made various attempts to do this including (Where Namespace_Module is my own module with a list.phtml)

<referenceBlock name="category.products.list" template="Namespace_Module::list.phtml" />

and

<referenceBlock name="category.products.list">
    <arguments>
        <argument name="template" xsi:type="string">%Namespace_Module::list.phtml%</argument>
    </arguments>
</referenceBlock>

Is there any restriction on overriding certain blocks? I can't see what is wrong with the above for this not to work?

To confirm, I'm applying this in the Category > Layout Update XML as that is the only place I can do it dynamically for a range of categories

I'm running Magento v2.1.3

Best Answer

I took a look the source code of Magento 2.1.3 version, it used <action method="setTemplate">:

<referenceBlock name="category.products.list">
     <action method="setTemplate">
        <argument name="template" xsi:type="string">%Namespace_Module::list.phtml%</argument>
     </action>
</referenceBlock>
Related Topic