Tutorialsplane

Magento 2 Show Static Block


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 block 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 diplay static block 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 diplay static block on 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>