The question:
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="MagentoCmsBlockBlock" name="block_identifier">
<arguments>
<argument name="block_id" xsi:type="string">block1</argument>
</arguments>
</block>
<block class="MagentoCmsBlockBlock" name="block_identifier" after="-">
<arguments>
<argument name="block_id" xsi:type="string">block2</argument>
</arguments>
</block>
How to show all blocks
The Solutions:
Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.
Method 1
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="MagentoCmsBlockBlock" name="block_identifier">
<arguments>
<argument name="block_id" xsi:type="string">block1</argument>
</arguments>
</block>
<block class="MagentoCmsBlockBlock" 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.
Method 2
You can do it in 2 ways.
From cms page add block to homage:
{{block class="MagentoCmsBlockBlock" block_id="block_identifier"}}
From Xml File:
<referenceContainer name="content">
<block class="MagentoCmsBlockBlock" name="block_identifier">
<arguments>
<argument name="block_id" xsi:type="string">block_identifier</argument>
</arguments>
</block>
</referenceContainer>
Hope this helps you
Method 3
Create Block
-
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.
-
Then click Add New Block.
-
Next, add the details of the Block -> Enter the Block Title (Title of the Block) and
Block Identifier (Id of the Block). -
Set Block Identifier=Demo_Test and add some text in content section.
-
Now just click Save.
Add Block to Homepage
-
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.
-
Click the Edit on the homepage.
-
Go to the content section and add block shortcode :
{{block class="MagentoCmsBlockBlock" block_id="Demo_Test"}} -
Click Save
Method 4
Best way is, go to the layout file and copy the block description
<block class="ItheavensFanpageBlockIndexIndex" name="index.index" template="Itheavens_Fanpage::index/index.phtml"/>
and replace it with second bracket be like this
{{block class="ItheavensFanpageBlockIndexIndex" name="index.index" template="Itheavens_Fanpage::index/index.phtml"}}
Method 5
block_identifier
Add in default.xml file under Magento_theme Folder which is placed under current applied theme.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0