我试图了解导航栏是如何在 magento 中形成的流程,并在 topmenu.phtml 中遇到了我无法弄清楚的这一行。
<?php $_menu = $this->getHtml('level-top') ?>
我知道如何调用子块,但是“顶级”在哪里?似乎是一个特殊的关键词。谁能解释这个定义在哪里以及它是如何与顶部导航相关联的?
提前致谢。
我试图了解导航栏是如何在 magento 中形成的流程,并在 topmenu.phtml 中遇到了我无法弄清楚的这一行。
<?php $_menu = $this->getHtml('level-top') ?>
我知道如何调用子块,但是“顶级”在哪里?似乎是一个特殊的关键词。谁能解释这个定义在哪里以及它是如何与顶部导航相关联的?
提前致谢。
是的,这有点奇怪,但归结为以下几点:
该调用$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
从那里您可以看到对$renderer->toHtml()
where$renderer
实例的调用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);
}
在我的情况下,此方法现在将模板文件加载到$includeFilePath
变量中/vagrant/app/design/frontend/rwd/default/template/page/html/topmenu/renderer.phtml
(取决于您使用的主题)。
我无法发现$outermostClass
value的任何用途top-level
。