Home » Magento4 December 2009

Magento: How to call block directly from phtml file without defining in layout?

You can call your block directly from a phtml file with the following code. You can keep this code and call the block from any phtml file.

I have assumed my module name as Newmodule and my block name as Newblock.php. The phtml file for the block is assumed to be newmodule/newblock.phtml

If you want to call the block from another module or another phtml template file then you can use the following code:



Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed
  • Hi,

    This worked great – many thanks! Is there a way to specify the product category to be show when calling, for example:

    getLayout()->createBlock('catalog/product_list')->setTemplate('catalog/product/list.phtml')->toHtml(); ?>


  • Sometimes I am using this approach too. But it’s recommended to create new block method for such purposes.

  • Naleen

    Thanks, It worked form me.