9

How to display static blocks in home page. I want to show static block in home in page.Iam overiding module_cms and add this code in cms_index-index but its 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

  • 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. – Rakesh Jesadiya Dec 6 '16 at 11:11
  • cms page? Rakesh – Nadh Dec 6 '16 at 11:23
  • Yes using cms page, call block inside cms page – Rakesh Jesadiya Dec 6 '16 at 11:23
  • how to call cms page in homepage.. can you give any example – Nadh Dec 6 '16 at 11:24
  • how to display it in home page – Nadh Dec 6 '16 at 11:26
9

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

You have to keep same block_identifier for both static block.

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.

  • nothing showing – Nadh Dec 7 '16 at 6:40
  • have you changed name same as above and have you create block1 and block2? – Rakesh Jesadiya Dec 7 '16 at 6:40
  • changed but not showing – Nadh Dec 7 '16 at 6:42
  • ok i got it its working – Nadh Dec 7 '16 at 6:45
  • if i add another block then – Nadh Dec 7 '16 at 6:46
16

You can do it 2 way.

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

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

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

  • need to add url as home? – Nadh Dec 6 '16 at 14:05
  • Which URL you are talking about ? – Syed Muneeb Ul Hasan Dec 6 '16 at 14:08
0

block_identifier

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

0

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"}}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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