Sign up ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

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

2 Answers 2

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 yesterday
    
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 yesterday

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.