2016-05-10 1 views
3

nav barがmagentoでどのように形成されているのかを理解しようとしていて、わからなかったtopmenu.phtmlでこの行を見つけました。magento:レベルトップを解読しようとしています

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

私はどのようにchildblocksが呼び出されるのですか? 'level-top'はどこですか?特別なキーワードのようです。誰がこれがどこに定義されているのか、これがトップのナビゲーションにどのようにリンクされているのかを説明できますか?

ありがとうございます。

答えて

2

はい、これは少し奇妙であるが、それは以下に要約:

$this->getHtml('level-top')ブロッククラスMage_Page_Block_Html_Topmenuを指すコール内部の方法で($thisすると、そのクラスのインスタンスです)

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あなたはへの呼び出しを参照してください。そこから値top-level

を保持しています$rendererMage_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); 
} 

この方法は、今私の場合/vagrant/app/design/frontend/rwd/default/template/page/html/topmenu/renderer.phtml(あなたが使用したテーマに応じて)で、$includeFilePath変数にテンプレートファイルをロードします。

top-levelの値を持つ$outermostClassの使用を見つけることができませんでした。

関連する問題