How to call block in observers Magento2?
Do you want to access a block thats in the layout? Or can you specify your question.
Yes i want to access a block through observer that is in the layout.
public function __construct(\Magento\Framework\View\LayoutInterface $layout)
{
$this->layout = $layout;
}
public function execute()
{
$block = $this->layout->createBlock('NameSpace\ModuleName\Block\ListProduct')->setTemplate('NameSpace_ModuleName::category/view.phtml')->toHtml();
echo "<prE>";
print_R($block);
exit;
}