class My_Custom_Block extends Mage_Core_Block_Template { public function getFoo() { return 'bar'; } } $my_custom_block = new My_Custom_Block(); echo $my_custom_block->getFoo();
class My_Product_Block extends Mage_Core_Block_Template { public function getProduct() { $product_id = $this->getRequest()->getParam('id'); $product = Mage::getModel('catalog/product')->load($product_id); return $product; } } $my_product_block = new My_Product_Block(); $my_product_block->setTemplate('my_product_template.phtml'); echo $my_product_block->toHtml();In this example, we define a custom product block class that extends Mage_Core_Block_Template. We then create a new instance of this class and call the `getProduct()` method, which retrieves a product object by its ID. We then set the block's template using the `setTemplate()` method and render it using the `toHtml()` method. Package library: Magento Framework.