首页 文章

Magento布局文件模板参考?

提问于
浏览
2

我研究过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>

它告诉我们, Headers 块中有一个top.links块

1 回答

  • 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 .

相关问题