Skip to main content

I have created a custom block page. I want to call custom block to another phtml file.

When I called custom block in xml file is working. 

But when I called custom block in phtml file is not working.

getLayout() ->createBlock('Codism\Csr\Block\Index\TopMenu') ->setBlockId('Codism_Csr::menu.phtml') ->toHtml(); ?>
<?php echo $block->getLayout() ->createBlock('Codism\Csr\Block\Index\TopMenu') ->setBlockId('Codism_Csr::menu.phtml') ->toHtml(); ?> 

I have created a custom block page. I want to call custom block to another phtml file.

When I called custom block in xml file is working. But when I called custom block in phtml file is not working.

getLayout() ->createBlock('Codism\Csr\Block\Index\TopMenu') ->setBlockId('Codism_Csr::menu.phtml') ->toHtml(); ?>

I have created a custom block page. I want to call custom block to another phtml file.

When I called custom block in xml file is working. 

But when I called custom block in phtml file is not working.

<?php echo $block->getLayout() ->createBlock('Codism\Csr\Block\Index\TopMenu') ->setBlockId('Codism_Csr::menu.phtml') ->toHtml(); ?> 
Source Link
Masud Shaikh
  • 1.2k
  • 22
  • 55

Magento2: How to call custom block in phtml file

I have created a custom block page. I want to call custom block to another phtml file.

When I called custom block in xml file is working. But when I called custom block in phtml file is not working.

getLayout() ->createBlock('Codism\Csr\Block\Index\TopMenu') ->setBlockId('Codism_Csr::menu.phtml') ->toHtml(); ?>