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

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
    – User0434
    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
    – User0434
    Commented Dec 6, 2016 at 11:24
  • how to display it in home page
    – User0434
    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.

8
  • nothing showing
    – User0434
    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
    – User0434
    Commented Dec 7, 2016 at 6:42
  • ok i got it its working
    – User0434
    Commented Dec 7, 2016 at 6:45
  • if i add another block then
    – User0434
    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

8
  • which xml file ..Kul
    – User0434
    Commented Dec 6, 2016 at 11:33
  • @Nadh cms_index_index.xml you can find it in view section of module-cms
    – Kul
    Commented Dec 6, 2016 at 11:43
  • need to overide that module?
    – User0434
    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
    – Kul
    Commented Dec 6, 2016 at 11:45
  • its not working
    – User0434
    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

2
  • need to add url as home?
    – User0434
    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"}}
0

block_identifier

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

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.