Magento – magento 2 add static block on category page left sidebar only

categorylayoutmagento-2.1magento2xml

I have override Module-Catalog into my theme's folder.

I want to add custom blocks in category sidebar. so in catalog_category_View.xml file i have added following code which works if i put it in default.xml file but it doesn't work for catalog_category_view.xml file.

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="sidebar.additional">
            <block class="Magento\Cms\Block\Block" name="top_left_sidebar">
                <arguments>
                    <argument name="block_id" xsi:type="string">top_left_sidebar</argument>
                </arguments>
            </block>
        </referenceContainer>
    </body>
</page>

I want to show that block for category page left column only. How can i do that?

Best Answer

You don't have to edit your xml files. Just add a cms block to your design layout.

In your Magento Backend go to the category>design insert into the xml layout update area

<referenceContainer name="sidebar.main">
        <block class="Magento\Cms\Block\Block" name="Your_CMS_Block">
            <arguments>
                <argument name="block_id" xsi:type="string">Your_CMS_Block</argument>
            </arguments>
        </block>
 </referenceContainer>

I always use the same name for both the cms block name and the identifier when I create the block.

The only reason I'd edit the XML for this is if you are building this shop for a client and you don't want them to be able to go in and change what you did.