Magento2 Layout Update XML – Add Block to Sidebar

layoutmagento2static-blockxml

When I create a new page in Magento 2 using the "two columns with left bar" layout it by default puts the wishlist in there.

Using the "layout update XML" in the design options tab I can remove that using this:

<referenceBlock name="wishlist_sidebar" remove="true"/>

What I also want to do is replace it with my own static block. I thought something like the following would do the trick but it does not. Can someone help?

<container name="sidebar.additional">
   <block class="Magento\Cms\Block\Block" name="test" />
</container>

Best Answer

To reference a container you need to use referenceContainer as opposite to referenceBlock to reference a block.

The container tag is used to create a container as the block tag is used to create a block.

In your case, the right code would be:

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

This is assuming your cms block id is test, you'll need to replace that value in case it is different