15

How to display static blocks in the home page. I want to show a static block on the home page.I am overriding module_cms and add this code in cms_index-index but it's showing only last block

<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" after="-">
    <arguments>
      <argument name="block_id" xsi:type="string">block2</argument>
    </arguments>
  </block>

How to show all blocks

Andhi Irawan
  • 986
  • 1
  • 14
  • 28
User0434
  • 1,155
  • 2
  • 15
  • 39

5 Answers5

31

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

Andhi Irawan
  • 986
  • 1
  • 14
  • 28
Kul
  • 1,777
  • 5
  • 29
  • 54
9

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.

Andhi Irawan
  • 986
  • 1
  • 14
  • 28
Rakesh Jesadiya
  • 42,221
  • 18
  • 132
  • 183
4

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

1

Best way is, go to the layout file and copy the block description

<block class="Itheavens\Fanpage\Block\Index\Index" name="index.index" template="Itheavens_Fanpage::index/index.phtml"/>

and replace it with second bracket be like this

{{block class="Itheavens\Fanpage\Block\Index\Index" name="index.index" template="Itheavens_Fanpage::index/index.phtml"}}
Rama Chandran M
  • 3,210
  • 13
  • 22
  • 38
0

        block_identifier


Add in default.xml file under Magento_theme Folder which is placed under current applied theme.