1

To get block in magento1 we use echo $this->getLayout()->createBlock('module/adminhtml_module_grid')->toHtml().

What is the similar function in magento2?

Vinaya Maheshwari
  • 2,174
  • 3
  • 34
  • 76

1 Answers1

1

You can do the same in Magento2 If your Block class extends Magento\Framework\View\Element\Template

$block->getLayout()->createBlock('something/something')->toHtml()

If your Block class does not extend Magento\Framework\View\Element\Template then you can Inject the \Magento\Framework\View\LayoutInterface in your block construct and you can use use this pattern.

Keyur Shah
  • 18,046
  • 6
  • 66
  • 80