1

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

What is the similar function in magento2?

3

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.