How to add a child block in Magento 2

- Magento 2

Magento 2 Development

You can rely on the $this->addChild function to add a child block in Magento 2. Check the following example:

Then it is necessary to use

in parent block template to render child block with the template. It’s better to utilize layout to define templates and blocks.

Source (Magento Stackexchange question) (KAndy)

More tips from the cookbook