Magento: How to create an instance of a block class?

user1638055 picture user1638055 · Aug 31, 2012 · Viewed 7.4k times · Source

In the core of Magento there is the app\code\core\Mage\Catalog\Block\Product\View\Options.php class for example.

How would I create an instance of that? I tried

Mage::getModel('Mage_Catalog_Block_Product_View_Options');

and it worked, but since this is not a Model class, but a Block class it seems wrong to create it that way. Whats the alternative to that?

Thanks! :)

Answer

Phil Birnie picture Phil Birnie · May 29, 2013

Use the createBlock method:

$block = $this->getLayout()->createBlock('catalog/product_view_options')