How to add a child block in Magento 2
You can rely on the $this->addChild function to add a child block in Magento 2. Check the following example:
1 2 3 4 5 |
$this->addChild( 'back_button', 'Magento\Backend\Block\Widget\Button', ['label' => __('Back'), 'template' => 'Vendor_Moduel::template.phtml' 'class' => 'cancel'] ); |
Then it is necessary to use
1 |
$this->getChildHtml('back_button') |
in parent block template to render child block with the template. It’s better to utilize layout to define templates and blocks.
Source (