Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In magento 1.x it is possible to add a static block using xml layout file.

<reference name="root">
        <block type="cms/block" name="name">
            <action method="setBlockId"><block_id>static-block-id</block_id></action>
        </block>
</reference>

But, in magento 2 how we can achieve it ?

share|improve this question

Finally I got the solution. You can call static block using following way.

<referenceContainer name="footer">
    <block class="Magento\Store\Block\Switcher" name="store_switcher" as="store_switcher" after="footer_links" template="switch/stores.phtml"/>

     <block class="Magento\Cms\Block\Block" name="test">
        <arguments>
            <argument name="block_id" xsi:type="string">promo</argument>
        </arguments>
    </block>
</referenceContainer>
share|improve this answer

It can be done easily from the admin panel by following the steps below.

  1. Go to Content -> Widgets
  2. Add New Widget
  3. Select type as CMS Static Block
  4. Select Design Package/Theme And Continue
  5. Set Widget Title, Store and Sort order in Storefront properties tab
  6. Select static block from in the Widget options tab
  7. Save the widget
  8. Click On Add Layout Update button
  9. Select Option from Display on dropdown e.g. : Specific page to display block on specifi

  10. Select Page from the Page dropdown

  11. Select Container from Container dropdown
  12. save the widget
share|improve this answer
    
It is useful to CMS pages only. Can we use it in our custom module xml too? – Praful Rajput Dec 9 '15 at 13:31
    
I have provided the cms page example only, you can use it for every possible module or page. you can get an idea by seeing the list of the option in the Display on dropdown – Taral Patoliya Dec 9 '15 at 13:46

If you want to call static-block in 2columns-left page, you can simply do it using,

here below you can change quickblock with your static-block identifier.

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

Above Block is working fine for 2columns-left with sidebar.

share|improve this answer

In the following code, change the "block_identifier" from the CMS block created on magento dashboard and add it to layout.xml. It works.

<referenceContainer name="footer">
       <block class="Magento\Cms\Block\Block" name="block_identifier">
            <arguments>
                <argument name="block_id" xsi:type="string">block_identifier</argument>
            </arguments>
        </block>
    </referenceContainer>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.