Magento – How to add a CMS Block via XML layout update in Magento 2

blockscms-blocklayoutmagento2

In order to create custom sidebar menus for my CMS pages in Magento 1, I used to be able to create a static block, and then use a widget to place it on all CMS pages that had a 2 column layout with left bar. That option is not available in Magento 2.

So, for Magento 2, I created a block called "guidenav", and I want it to appear on certain CMS pages, and for those CMS pages I can use this code in Layout Update XML:

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

The block isn't showing up. Any ideas?

Best Answer

I found the solution in case this will help anyone. In Magento 2, if you want to create a left side bar navigation, (and remove wishlist and compare), you need the following code in the CMS Page Layout Update XML (I dont like editing files if I dont have to, thats why I like sysing Layout Update XML). My block is called "guidenav" that calls the menu.

<referenceContainer name="sidebar.additional">
<referenceBlock name="catalog.compare.sidebar" remove="true"/>
<referenceBlock name="wishlist_sidebar" remove="true" />
<referenceBlock name="sale.reorder.sidebar" remove="true" />
    <block class="Magento\Cms\Block\Block" name="guidenav">
        <arguments>
            <argument name="block_id" xsi:type="string">promo</argument>
        </arguments>
    </block>
</referenceContainer>