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
9821 gold badge14 silver badges28 bronze badges
asked Dec 6, 2016 at 11:04
9
  • You can set using page as well as layout file. Using Page you can set anywhere inside homepage and its easy to manage compare to layout file. Commented Dec 6, 2016 at 11:11
  • cms page? Rakesh Commented Dec 6, 2016 at 11:23
  • Yes using cms page, call block inside cms page Commented Dec 6, 2016 at 11:23
  • how to call cms page in homepage.. can you give any example Commented Dec 6, 2016 at 11:24
  • how to display it in home page Commented Dec 6, 2016 at 11:26

5 Answers 5

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
9821 gold badge14 silver badges28 bronze badges
answered Dec 7, 2016 at 6:13
8
  • nothing showing Commented Dec 7, 2016 at 6:40
  • have you changed name same as above and have you create block1 and block2? Commented Dec 7, 2016 at 6:40
  • changed but not showing Commented Dec 7, 2016 at 6:42
  • ok i got it its working Commented Dec 7, 2016 at 6:45
  • if i add another block then Commented Dec 7, 2016 at 6:46
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
9821 gold badge14 silver badges28 bronze badges
answered Dec 6, 2016 at 11:29
8
  • which xml file ..Kul Commented Dec 6, 2016 at 11:33
  • @Nadh cms_index_index.xml you can find it in view section of module-cms Commented Dec 6, 2016 at 11:43
  • need to overide that module? Commented Dec 6, 2016 at 11:44
  • If you don't have this module in your theme you can copy from Vendor/magento/ otherwise no need to override Commented Dec 6, 2016 at 11:45
  • its not working Commented Dec 6, 2016 at 11:54
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

answered Dec 6, 2016 at 12:58
2
  • need to add url as home? Commented Dec 6, 2016 at 14:05
  • Which URL you are talking about ? Commented Dec 6, 2016 at 14:08
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,26515 gold badges24 silver badges38 bronze badges
answered Nov 7, 2017 at 12:12
0

block_identifier

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

answered Dec 6, 2016 at 12:42

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.