Magento布局文件模板参考?

时间:2011-10-27 06:41:04

标签: magento

我研究过Magento Template基础教程。有一个问题使我困惑。

在checkout.xml中查看这段代码。它告诉我系统将在top.links块中添加两个链接。

<reference name="top.links">
     <block type="checkout/links" name="checkout_cart_link">
         <action method="addCartLink"></action>
         <action method="addCheckoutLink"></action>
     </block>
</reference>

所以我在page.xml布局文件中找到了top.links块。我想知道这个块将使用哪个模板。但是此标记中没有模板属性。所以任何人都可以告诉我为什么这里没有模板属性?如果是这样,Magento如何知道应该引用哪个模板?

<block type="page/html_header" name="header" as="header">
    <block type="page/template_links" name="top.links" as="topLinks"/>
</block>

它告诉我们,标题栏中有一个top.links块

1 个答案:

答案 0 :(得分:10)

在布局XML中,您可以看到块的类别名为page/template_links。这意味着块的PHP类是Mage_Page_Block_Template_Links。打开文件app/code/core/Mage/Page/Block/Template/Links.php以查看块的行为方式。并非所有块都有模板文件,但在类定义中看起来应该是:

class Mage_Page_Block_Template_Links extends Mage_Core_Block_Template

继续阅读,您将看到模板文件在构造函数中设置:

protected function _construct()
{
    $this->setTemplate('page/template/links.phtml');
}

因此,您要查找的模板文件为page/template/links.phtml