Three Ways to Show a CMS Block in Magento 2

Three Ways to Show a CMS Block in Magento 2

CMS blocks let your team edit content such as banners and footer text in the admin. Magento 2 gives you three ways to place them.

In layout XML

Best for site-wide areas like the footer:

<referenceContainer name="footer-container">
      <block class="Magento\Cms\Block\Block" name="footerstaticblock" after="-" >
        <arguments>
          <argument name="block_id" xsi:type="string">footerstaticblock</argument>
        </arguments>
      </block>
    </referenceContainer>

In a template

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

Inside CMS content

Use this directive in a CMS page or block:

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

Replace block_identifier with the identifier you set in Content > Blocks.

Stuck on something similar? Our Magento development team is happy to take a look.

Keep reading

Related articles

All articles

Need a hand?

Stuck on something similar?
We can fix it with you.

Send us the problem. A senior developer reads every message and replies within one working day.