Is there a simple way as in magento1 :

 $crumbs = Mage::app()->getLayout->getBlock('breadcrumbs');


I wish it was that easy.
It depends on where you want to instantiate it from.
If you want to create an instance from inside an other block do it like this:


From inside a controller do this:


From inside a model:


but here there is a catch.
you have to create a protected member on the model called _blockFactory and inject an instance of \Magento\Framework\View\Element\BlockFactory in the constructor and assign it to that member var.

Something like this:

protected $_blockFactory;
public function __construct(
   \Magento\Framework\View\Element\BlockFactory $blockFactory,
    $this->_blockFactory = $blockFactory;

For instantiating a block from inside a helper it works the same as for model

| improve this answer | |
  • the simpler the better – Matoeil Aug 21 '14 at 8:03
  • @Marius $toplink = $this->getLayout()->getBlock('top.links')->toHtml(); use in magento 1 for magento 2 $this->_view->getLayout()->getBlock(Full\Block\Class\Name\Here')->toHtml(); this give a error like this Fatal error: Call to a member function toHtml() on a non-object how can i get toHtml()? – ND17 Jan 28 '16 at 13:31
  • if you are in a controller, you don't need to inject anything for _view. It should be available by default, although I think it's deprecated now. I wrote this answer 1.5 years ago – Marius Jan 28 '16 at 13:36
  • 1
    @SachinS. You should not use that anymore. _view is deprecated now in controllers and it will soon go away, – Marius Sep 27 '16 at 7:36
  • 1
    Can i call using pagefactory object like this? $viewPanelPageFactory=$this->resultPageFactory->create(); $viewPanel= $viewPanelPageFactory->getLayout()->getBlock('catalog.leftnav')->toHtml(); – Sushivam Sep 27 '16 at 7:40

To instantiate a block you have to use \Magento\Framework\View\LayoutInterface class and its createBlock() method.

With an helper class you could do it with this code:

namespace Vendor\Module\Helper;

class Data extends \Magento\Framework\App\Helper\AbstractHelper

     * Layout
     * @var \Magento\Framework\View\LayoutInterface
     protected $_layout;

     public function __construct(
        \Magento\Framework\App\Helper\Context $context,
        \Magento\Framework\View\LayoutInterface $layout
     ) {
         $this->_layout = $layout;

     * Create new block
     public function getBlock() {

        $block = $this->_layout

        return $block;



Then call $helper->getBlock() from where you need.

| 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.