How can I create multiple category pages in Magento 2?
-
17-12-2020 - |
Question
Actually, I want to create different files for every category page (every product listing page).
For that I have:
Created customlist.phtml from list.phtml or copied the code of list.phtml and create
Assign customlist.phtml in admin side (admin → category → Layout section)
But it is not working:
Error:-
Fatal error: Uncaught Error: Call to a member function count() on null
Layout Section Code:
<referenceContainer name="content">
<referenceBlock name="category.products">
<block name="product_list" class="Magento\Catalog\Block\Navigation">
<action method="setTemplate">
<argument name="template" xsi:type="string">Magento_Catalog::product/customlist.phtml</argument>
</action>
</block>
</referenceBlock>
</referenceContainer>
How can I create multiple category pages in Magento 2?
Solution
@jaimin for toolbar you need to do something like this.
<referenceContainer name="content">
<referenceBlock name="category.products">
<block name="product_list" class="Magento\Catalog\Block\Product\ListProduct">
<action method="setTemplate">
<argument name="template" xsi:type="string">Magento_Catalog::product/list2.phtml</argument>
</action>
<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\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>
</referenceBlock>
</referenceContainer>
OTHER TIPS
you mention wrong block name please check below code
<referenceContainer name="content">
<referenceBlock name="category.products">
<block name="product_list" class="Magento\Catalog\Block\Product\ListProduct">
<action method="setTemplate">
<argument name="template" xsi:type="string">Magento_Catalog::product/customlist.phtml</argument>
</action>
</block>
</referenceBlock>
</referenceContainer>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange