Static blocks are blocks that help to display different type of content on one or multiple pages for advertising purposes. It can be a banner, sidebars, images or other pieces of content.

If you want to call static block, please follow our small guide.

How to Add Static Block In XML File

To add a static block in XML file use:

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

How to Call Static Block in Magento 2 CMS Page

To create static block in Magento CMS page, use the following steps:

Step 1. Go to the Admin Panel of the Magento store, navigate to the Content tab from the left corner of the page and then click on the Pages option.

Magento Admin. Content. Pages section

Step 2. Click the Edit on the [Your Page].

Admin Panel. Edit "Your" Page

Step 3. Go to the Content section and add block code:

{{block class="Magento\Cms\Block\Block" block_id="[Identifier]"}}

Add code to the Content block

Step 4. Click Save.

How to Call Phtml File in CMS Page in Magento

This will help you to call a Phtml file in CMS static block as well. To do it, you need:

Step 1. Go to the Admin Panel of the Magento store, navigate to the Content tab from the left corner of the page and then click on the Pages option.

Step 2. Click the Edit on the [Your Page].

Step 3. Go to the Content section and add block code:

{{block class="[BlockClassFullName]" template="[VendorName]_[ModuleName]::[YourTemplateFileLocation].phtml"}}

For example:

{{block class="Magento\Bannerslider\Block\Slideshow" template="Magento_Bannerslider::bannerslider.phtml"}}

Step 4. Click Save.

How to Add Static Block in Magento via Phtml File

To call static block in Magento via Phtml file, use the following block code:

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

Now you know how to call static block in Magento using Phml file, XML file, and CMS page.

4.89 / 5.0
Article rating (9 Reviews)
Do you find this article useful? Please, let us know your opinion and rate the post!
Not badGoodVery GoodGreatAwesome