3

I am trying to understand the flow of how the nav bar is being formed in magento and came across this line in topmenu.phtml that i could not figure out.

<?php $_menu = $this->getHtml('level-top') ?>

I get how childblocks are called, but where is 'level-top'? Seems like a special key word. Can anyone explain where is this defined and how this is linked to the top nav?

Thanks in advance.

codedge
  • 4,754
  • 2
  • 22
  • 38
shriekz
  • 55
  • 2
  • 5

1 Answers1

2

Yes, this is a bit weird but it boils down to the following:

The call $this->getHtml('level-top') refers to the block class Mage_Page_Block_Html_Topmenu ($this is an instance of that class) with the method inside:

public function getHtml($outermostClass = '', $childrenWrapClass = '')
{
    Mage::dispatchEvent('page_block_html_topmenu_gethtml_before', array(
        'menu' => $this->_menu,
        'block' => $this
    ));

    $this->_menu->setOutermostClass($outermostClass);
    $this->_menu->setChildrenWrapClass($childrenWrapClass);

    if ($renderer = $this->getChild('catalog.topnav.renderer')) {
        $renderer->setMenuTree($this->_menu)->setChildrenWrapClass($childrenWrapClass);
        $html = $renderer->toHtml();
    } else {
        $html = $this->_getHtml($this->_menu, $childrenWrapClass);
    }

    Mage::dispatchEvent('page_block_html_topmenu_gethtml_after', array(
        'menu' => $this->_menu,
        'html' => $html
    ));

    return $html;
}

--> $outermostClass holds the value top-level

From there you see the call to $renderer->toHtml() where $renderer is an instance of Mage_Page_Block_Html_Topmenu_Renderer.

protected function _toHtml()
{
    $this->_addCacheTags();
    $menuTree = $this->getMenuTree();
    $childrenWrapClass = $this->getChildrenWrapClass();
    if (!$this->getTemplate() || is_null($menuTree) || is_null($childrenWrapClass)) {
        throw new Exception("Top-menu renderer isn't fully configured.");
    }

    $includeFilePath = realpath(Mage::getBaseDir('design') . DS . $this->getTemplateFile());
    if (strpos($includeFilePath, realpath(Mage::getBaseDir('design'))) === 0 || $this->_getAllowSymlinks()) {
        $this->_templateFile = $includeFilePath;
    } else {
        throw new Exception('Not valid template file:' . $this->_templateFile);
    }
    return $this->render($menuTree, $childrenWrapClass);
}

This method now loads the template file into the $includeFilePath variable, in my case /vagrant/app/design/frontend/rwd/default/template/page/html/topmenu/renderer.phtml (depending on the theme you use).

I couldn't spot any use of $outermostClass with the value top-level.

codedge
  • 4,754
  • 2
  • 22
  • 38