How i include a static block in a page using xml. For example i created a static block with identifier promo. In magento 1 we include a static block using below code

     <block type="cms/block" name="Promo">
          <action method="setBlockId"><block_id>promo</block_id></action>
     </block> 

I want to do exactly same in magento 2

up vote 30 down vote accepted
<block class="Magento\Cms\Block\Block" name="Promo">
    <arguments>
        <argument name="block_id" xsi:type="string">promo</argument>
    </arguments>
</block>

is the equivalent to M1 ?

  • @Ben-Space48, agree – KAndy May 3 '16 at 16:27

Correct xml instructions for current Magento2 version should be:

<block class="Magento\Cms\Block\Block" name="Promo">
    <arguments>
        <argument name="block_id" xsi:type="string">promo</argument>
    </arguments>
</block>

Hope this helps!

Try below code.

Call from Phtml File:

<?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('block_identifier')->toHtml();?>

Call from cms page or block:

{{block class="Magento\\Cms\\Block\\Block" block_id="block_identifier"}}

Call from Xml File:

<referenceContainer name="content">
    <block class="Magento\Cms\Block\Block" name="block_identifier">
        <arguments>
            <argument name="block_id" xsi:type="string">block_identifier</argument>
        </arguments>
    </block>
</referenceContainer>

Hope this helps you!

Call from Xml File worked. Change the "block_identifier" from the CMS block created on magento dashboard and add it to layout.xml

<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>
 <referenceContainer name="content">
      <block class="Magento\Cms\Block\Block" name="daily_deals" template="bigbazaar.phtml">
        <arguments>
            <argument name="block_id" xsi:type="string">daily_deals</argument>
        </arguments>
    </block>
 </referenceContainer>

Here daily_deals is my CMS block identifier's name. I wish it should work..

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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