3

Actually, I want to create different files for every category page (every product listing page).

For that I have:

  1. Created customlist.phtml from list.phtml or copied the code of list.phtml and create

  2. 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?

3
  • can you please paste your admin->category->Layout section code Nov 24 '17 at 10:42
  • @SunilPatel i have updated code now
    – Jaimin
    Nov 24 '17 at 10:45
  • @SunilPatel when i add custom text like echo "hello"; then it is working but after copy all code of list.phtml it shows error.
    – Jaimin
    Nov 24 '17 at 10:46
2

@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>
4

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>
3
  • Perhaps you could reveal the wrong block name? Nov 24 '17 at 16:40
  • @Sunil Patel I have found one issue after adding your given code. I could not see pagination in my custom listing page. except that all are working as expected. can you help me in that please
    – Jaimin
    Nov 12 '18 at 13:20
  • Maybe you need to change Block. Nov 12 '18 at 13:27

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.