Magento2 : display static blocks in home page

You can do it in 2 ways.

From cms page add block to homage:

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

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

Hope this helps you


Keep below XML in your cms_index_index.xml file and check-in front,

You have to keep the same block_identifier for both static blocks.

You have to keep static block name as unique,

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

        <block class="Magento\Cms\Block\Block" name="block_identifier-second" after="-">
            <arguments>
                <argument name="block_id" xsi:type="string">block2</argument>
            </arguments>
        </block>
   </referenceContainer>

Replace block1 and block2 with your static block id in above XML code.


Create Block

  1. Go to the Admin Panel of the Magento Store and navigate to the Content tab from the left corner of the page. Next, click the Blocks option.

  2. Then click Add New Block.

  3. Next, add the details of the Block -> Enter the Block Title (Title of the Block) and Block Identifier (Id of the Block).

  4. Set Block Identifier=Demo_Test and add some text in content section.

  5. Now just click Save.

Add Block to Homepage

  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 Page option.

  2. Click the Edit on the homepage.

  3. Go to the content section and add block shortcode : {{block class="Magento\Cms\Block\Block" block_id="Demo_Test"}}

  4. Click Save

Tags:

Magento2