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
1 Answer 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();
} ?>
-
Since it's for a particular category you can't edit this list.phtml as it will affect every categoriesHaerriz– Haerriz2024年11月26日 08:34:03 +00:00Commented Nov 26, 2024 at 8:34
-
You can edit brother, just add condition based on current category idGohil Rajesh– Gohil Rajesh2024年11月26日 09:29:31 +00:00Commented Nov 26, 2024 at 9:29
-
I guess below one work for get category id
$categoryId = (int)$this->getRequest()->getParam('id', false);Gohil Rajesh– Gohil Rajesh2024年11月26日 10:52:30 +00:00Commented Nov 26, 2024 at 10:52 -
Does this count as Magento standardized way? What if client comes up with multiple categories like these?Haerriz– Haerriz2024年11月26日 10:55:01 +00:00Commented 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.Gohil Rajesh– Gohil Rajesh2024年11月26日 10:57:56 +00:00Commented Nov 26, 2024 at 10:57