Overriding Frontend / Adminhtml blocks - Magento Development

Today i’ve been trying to override adminhtml/page_menu block and the corresponding template file page/menu.phtml. I need to update a function getMenuLevel(), which basically generates the html for the menu in admin panel. Needless to say, with magento’s awesome flexibility it turns out to be a piece of cake (although i did spend an hour on a stupid typo).


<?xml version="1.0" encoding="UTF-8"?>

  <!-- Global -->

blocks node tell magento about the blocks in our module. market_adminhtml is the unique identifier to the blocks we’re gonna include in our module. market_adminhtml>class defines the class prefix for our blocks. Since we’re not going to create new blocks, those nodes are not important.

adminhtml node is the unique id to the blocks defined in app/code/core/Mage/Adminhtml/Block/, you can verify the same in config.xml for the Mage/Adminhtml module. Inside the rewrite node we suggest magento to use Market_Adminhtml_Block_Page_Menu class whenever a block of type adminhtml/page_menu is requested.


class Market_Adminhtml_Block_Page_Menu extends Mage_Adminhtml_Block_Page_Menu{

  public function foo(){
    return "<h1>foo</h1>";

  public function getMenuLevel($menu, $level = 0)
    $html = "";
    return $html;

The only thing you gotta remember is to extend the block we’re going to override (Mage_Adminhtml_Block_Page_Menu here), so you can keep the existing block functionalities. As you can figure out, i’ve overridden only getMenuLevel() function, for the rest of the functions magento still refers to the overridden class.

That’s all. The procedure is similar for frontend blocks too. Hope this helps.

Beware of typos

I closely spend an hour on a typo in my config.xml. Market_AdminHtml_Block_Page_Menu (with a capital ‘h’ in ‘Adminhtml’) instead of Market_Adminhtml_Block_Page_Menu. Kinda hard to recognize, but it’ll still confuse magento. Hope you don’t make such silly mistakes.