Magento 2 How To Call CMS Static Block in phtml File

In Magento 2, if you want to call CMS static block in templates, there are three ways to call CMS blocks:

1) You can call your static block in phtml file with following direct method call:

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

2) If you want to display CMS static block in CMS content from admin CMS block edit page, you can use the following:

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

3) If you want to display CMS static block through layout XML files, you can use the following:

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

Leave a Reply