Sometimes you want to call a block inside a .phtml file without defining in layout. In this case, we can use a method called toHtml of a block.

Assume that we have a block called Mymodule and a template that is located at: mymodule/myblog.phtml

So to generate that block we use:

<?php echo $this->getLayout()->createBlock('mymodule/myblock')->setTemplate('mymodule/myblock.phtml')->toHtml(); ?>

Leave a Reply

Your email address will not be published.