Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

magento: trying to decipher level-top

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.

like image 877
shriekz Avatar asked Dec 05 '25 05:12

shriekz


1 Answers

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.

like image 99
codedge Avatar answered Dec 08 '25 23:12

codedge



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!