2

I want to add a static block to left column of a 2 column layout via layout Update XML in Magento 2.1.1

Jumaanji
  • 51
  • 3

1 Answers1

1

In your custom theme Magento_Theme/layout/default.xml file add:

    <referenceContainer name="sidebar.main">
        <block class="Magento\Cms\Block\Block" name="any.name" after="-">
            <arguments>
                <argument name="block_id" xsi:type="string">your-cms-block-id</argument>
            </arguments>
        </block>
    </referenceContainer>

This will add a static block to all pages with left column. If you need to apply to a specific CMS page then you can add above code to CMS Page >EDIT>DESIGN>Layout Update XML

Devtype
  • 3,008
  • 3
  • 24
  • 36
  • Many Thanks for a prompt reply and i got an instant result. Instead updating Magento_Theme/layout/default.xml - I use a Custom CMS Page >EDIT>DESIGN>Layout Update XML exactly as per the code provided by Devtype. As the static block is specifically designed for the Custom CMS, hopefully, it is as per Magento guidelines. – Jumaanji Nov 02 '16 at 10:45
  • 1
    Glad it worked, I've edited answer to add info about adding layout update to specific cms page so it can benefit others, please accept the answer. – Devtype Nov 02 '16 at 11:07
  • I further try to call different static block in CMS PAGE (referenceContainer name="columns") which is the parent of left & right column. It went ok in a desktop view means the two block display below left and right column just before footer block but it is reverse in mobile browser. – Jumaanji Nov 03 '16 at 12:30
  • Referencing columns is bit tricky, I would advise referencing "content" container instead and using before and after directives for positioning. – Devtype Nov 03 '16 at 12:42
  • I use "content" instead of "columns" using after directives as after="-". It add static block to the right column. – Jumaanji Nov 04 '16 at 08:27
  • to add a static block just after the two column content before footer. I finally use following code which works well in desktop as well as mobile view. YOUR BLOCK ID – Jumaanji Nov 04 '16 at 08:31
  • Using firebug, i distinguish that "column" is the parent
    of "main" (right column) and "sidebar-main" (left column).

    i thank you Devtype for its assistance to conclude this thread. Adding static block via layout update xml of a CMS page is on piece of cake.

    – Jumaanji Nov 04 '16 at 08:35