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
-
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– Rakesh Jesadiya2016年12月06日 11:11:34 +00:00Commented Dec 6, 2016 at 11:11
-
cms page? RakeshUser0434– User04342016年12月06日 11:23:05 +00:00Commented Dec 6, 2016 at 11:23
-
Yes using cms page, call block inside cms pageRakesh Jesadiya– Rakesh Jesadiya2016年12月06日 11:23:42 +00:00Commented Dec 6, 2016 at 11:23
-
how to call cms page in homepage.. can you give any exampleUser0434– User04342016年12月06日 11:24:12 +00:00Commented Dec 6, 2016 at 11:24
-
how to display it in home pageUser0434– User04342016年12月06日 11:26:13 +00:00Commented Dec 6, 2016 at 11:26
5 Answers 5
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.
-
-
have you changed name same as above and have you create block1 and block2?Rakesh Jesadiya– Rakesh Jesadiya2016年12月07日 06:40:40 +00:00Commented Dec 7, 2016 at 6:40
-
changed but not showingUser0434– User04342016年12月07日 06:42:43 +00:00Commented Dec 7, 2016 at 6:42
-
ok i got it its workingUser0434– User04342016年12月07日 06:45:46 +00:00Commented Dec 7, 2016 at 6:45
-
if i add another block thenUser0434– User04342016年12月07日 06:46:08 +00:00Commented Dec 7, 2016 at 6:46
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
-
-
@Nadh
cms_index_index.xmlyou can find it in view section of module-cmsKul– Kul2016年12月06日 11:43:01 +00:00Commented Dec 6, 2016 at 11:43 -
need to overide that module?User0434– User04342016年12月06日 11:44:11 +00:00Commented 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 overrideKul– Kul2016年12月06日 11:45:43 +00:00Commented Dec 6, 2016 at 11:45 -
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="Magento\Cms\Block\Block" block_id="Demo_Test"}}Click Save
-
need to add url as home?User0434– User04342016年12月06日 14:05:00 +00:00Commented Dec 6, 2016 at 14:05
-
Which URL you are talking about ?Syed Muneeb Ul Hasan– Syed Muneeb Ul Hasan2016年12月06日 14:08:01 +00:00Commented Dec 6, 2016 at 14:08
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"}}
block_identifier
Add in default.xml file under Magento_theme Folder which is placed under current applied theme.