【问题标题】:Magento Layout File Template Reference?Magento 布局文件模板参考?
【发布时间】:2011-10-27 06:41:04
【问题描述】:

我学习了 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>

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

【问题讨论】:

    标签: magento


    【解决方案1】:

    在您的布局 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-05
      • 1970-01-01
      • 1970-01-01
      • 2015-11-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多