0

How do I add a cms block for a particular category above the pagination toolbar and below the products grid?

<referenceBlock name="product_list_toolbar">
 <block class="Magento\Cms\Block\Block" name="accessories.stand.out" before="-">
 <arguments>
 <argument name="block_id" xsi:type="string">accessories_stand_out</argument>
 </arguments>
 </block>
</referenceBlock> 

app/design/frontend/cb/vannicholas/Magento_Catalog/layout/catalog_category_view_id_4.xml

I have added it for the category 4. I don't get any error neither the CMS block is rendering

asked Nov 25, 2024 at 10:23

1 Answer 1

1

Simply override list.phtml in your theme and add code in phtml file for call cms block over there.

vendor/magento/module-catalog/view/frontend/templates/product/list.phtml

to

app/design/frontend/Your/Theme/Module_Catalog/template/catalog/product/list.phtml

and add your code above this line

<?= $block->getChildBlock('toolbar')->setIsBottom(true)->toHtml() ?>

<?php if ($categoryId = yourId) {
 echo $this->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('accessories_stand_out')->toHtml(); 
} ?>
answered Nov 26, 2024 at 7:04
6
  • Since it's for a particular category you can't edit this list.phtml as it will affect every categories Commented Nov 26, 2024 at 8:34
  • You can edit brother, just add condition based on current category id Commented Nov 26, 2024 at 9:29
  • I guess below one work for get category id $categoryId = (int)$this->getRequest()->getParam('id', false); Commented Nov 26, 2024 at 10:52
  • Does this count as Magento standardized way? What if client comes up with multiple categories like these? Commented Nov 26, 2024 at 10:55
  • so how you can manage with xml? you need to create seprate xml based on category id, yes this is the way only. you can do one thing, configure categories id from admin, add one configuration for add comma separated category ids and if match those id against current category id then show this block. Commented Nov 26, 2024 at 10:57

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.