In this article, we will explain how to call a CMS static block in Magento 2.
Before calling the CMS block, you must first create a static block in Magento 2.
Step 1: Log in to Magento 2 and go to Content -> Blocks. Click “Add New Block”, fill in the below details, and save your configuration.
Step 2: Add your code to the block content. And then click the save button. When the static block is saved, it appears in the grid.
Now we can call the newly created static block from a layout XML, CMS page, and PHTML 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>
{{block class="Magento\Cms\Block\Block" block_id="block_identifier"}}
<?= $this->getLayout() ->createBlock('Magento\Cms\Block\Block') ->setBlockId('block_identifier') ->toHtml(); ?>
That’s it! I hope this technical blog will help you find what you were looking for.
If you have any further questions about Magento 2 cms static block or if you need any help from our Magento 2 expert, contact us now for a free consultation.
Bookmark it for your future reference. Do comment below if you have any other questions.
P.S. Do share this note with your team.
Do not miss a chance to grab exciting offers on Magento Development at Dolphin Web Solution. We are providing discounts on various Magento services this season. Go and grab yours today at our Magento Store.