2

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

  • Is there any reasons that you didn't insert blocks directly under content? – PY Yick Aug 21 '17 at 3:40
  • @PYYick the main reason, if i want to disable the module, then automatically the block wont be loaded again – simple guy Aug 21 '17 at 4:17
  • How about if you use <body> to embed <referenceBlock>? – PY Yick Aug 21 '17 at 4:42
2

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>
| improve this answer | |
  • 1
    We need to put inside <body></body>. – Khoa TruongDinh Aug 21 '17 at 6:19
0

I think there is some problem with you XML code

correct like this.

<?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>
      <referenceContainer name="content">
     <block class="Test\Customlayout\Block\Sellerform" name="sellerform" template="Test_Customlayout::sellerform.phtml"/>
      </referenceContainer>
    </body>
</page>
| improve this answer | |

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.