Magento2 - How to show a block content on homepage

  • How to show a block content on homepage?

    After install magento2 without sample data, I chose 'Magento Luma' theme and add 'Home Page Block' block and copy the code from the sample store.

    but nothing show up on the home page, how to show my cms block on home page like sample store?

    my home enter image description here

    sample store

    enter image description here

    You mean showing custom cms block text/content or admin panel created cms block text/content?

    @magentotwo I create a custom cms block I want to know how to show this blcok on home page

    have you tried below solution?

    The home page content in sample data is coming from widgets.

  • in admin panel go to Content->Pages and edit home page and if you created your static block from admin panel add following to the Content tab

    {{block class="Magento\Cms\Block\Block" block_id="your_block_identifier"}}

    and if you created a custom block using a module add following to home page content tab

    {{block class="Vendor\ModuleName\Block\BlockName" template="Vendor_ModuleName::yourcustomblock.phtml"}} 

    then save the changes and flush magento cache and deploy/delete static contents now refresh home page .

    If this was not worked let me know

    It works like a charm! Thanks a lot Chamal!

    Is there any link I can learn more about this? magento block class and block id code for front-end?

    I found this is a good guide for understanding magento 2 block architecture

    From my module's `cms_index_index.xml`, I added this in Home Page content - ` and It says `Error filtering template: Invalid template file: 'Vendor_Module::module.phtml' in module: 'Vendor_Module' block's name: 'index_0'``

    ifconfig is not working with this approach. Any idea ?

License under CC-BY-SA with attribution

Content dated before 7/24/2021 11:53 AM