Magento 2 Show Static Block– It is very simple to display the static blocks on phtml, CMS page & XML in Magento 2. Here in this tutorial, we are going to explain how you can show static blocks on phtml, CMS page, or in XML using block identifier.
Magento 2 Show Static Block Example
Let us go one by one to see how to display the static block in XML, phtml & CMS page
On Phtml
You can display static blocks in Magento 2 using the following syntax.
Magento 2 Show Static Block in Phtml Example:
<?php
echo $this->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('block_identifier')->toHtml();
?>
On CMS Page
Now let us see how to display static block on the CMS page in Magento 2.
Magento 2 Show Static Block in Phtml Example:
{{block class="Magento\\Cms\\Block\\Block" block_id="block_identifier"}}
In XML File
You can also display static blocks using Layout XML.
Magento 2 Show Static Block in Phtml Example:
<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 article will help you in some way, You can see useful articles in the next articles.
Anything you need support from Magento 2 feels free to contact us at Alothemes and
Phone: (+84)865633728
Email: support@alothemes.com