How to add child block in Magento 2





Say if you want to add a child block in Customer account edit form page, write below code in customer_account_edit.xml of your theme structure app/design/frontend/MyPackage/Theme/Magento_Customer/layout/customer_account_edit.xml 

<referenceBlock name="customer_edit">
   <block class="Magento\Framework\View\Element\Template" name="attribute_customer_edit" template="attributes.phtml" cacheable="false" />
</referenceBlock>

Include child block in file Edit form Page app/design/frontend/MyPackage/Theme/Magento_Customer/templates/form/edit.phtml

<?php echo $block->getChildHtml('attribute_customer_edit'); ?> 

No comments:

Post a Comment

Buy/Sell Source Code of Website,Apps,Softwares

Install sample data in magento 2