How to instantiate a custom block in Magento 2

- Magento 2

Magento 2 Development

Unfortunately, the process is not as easy as in Magento 1 ($crumbs = Mage::app()->getLayout->getBlock(‘breadcrumbs’);). In Magento 2, it depends on where you are going to instantiate it from. To create an instance from another block, use the following code:

from a controller:

from a model and a helper:

Please note that in a case of the model you have to create _blockFactory (a protected member), and inject a \Magento\Framework\View\Element\BlockFactory instance in the constructor, assigning it to the member var. For instance:

More tips from Magento 2 Developer’s Cookbook

Source (Magento Stackexchange Question) (Marius)