Magento – Insert block inside static block magento 2

cms-blockhome-pagelayoutmagento2static-block

I create static block with reference name 'seller_registration_form' from Magento 2 backend which loaded in home page like this:

enter image description here

Now i want to insert additional content from my module, so i created cms_index_index.xml:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
  <referenceBlock name="seller_registration_form">
     <block class="Test\Customlayout\Block\Sellerform" name="sellerform" template="Test_Customlayout::sellerform.phtml"/>
  </referenceBlock>
</page>

but the phtml file never loaded in home page, i already make sure the block file in correct place and the phtml inside view/frontend/templates folder

Best Answer

You didn't place your <referenceBlock> inside <body></body>. In Layout file types from official document:

Page layout declares the wireframe of a page inside the section

Also in same official document:

<body></body> is the parent of <referenceBlock>

So in your cms_index_index.xml, you should embed <referenceBlock> with <body>. So that:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="seller_registration_form">
            <block class="Test\Customlayout\Block\Sellerform" name="sellerform" template="Test_Customlayout::sellerform.phtml"/>
        </referenceBlock>
    </body>
</page>
Related Topic