我学习了Magento Template基础教程。有一个问题让我很困惑。
看看checkout.xml中的这段代码。它告诉我系统将在 top.links block 中添加两个链接。
<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 block 。我想知道这个 block 将使用哪个模板。但是这个标签中没有模板属性。所以谁能告诉我为什么这里没有模板属性?如果那样,Magento 怎么知道应该引用哪个模板?
<block type="page/html_header" name="header" as="header">
<block type="page/template_links" name="top.links" as="topLinks"/>
</block>
它告诉我们,header block 中有一个 top.links block
最佳答案
在您的布局 XML 中,您可以看到 block 的类别名是 page/template_links
。这意味着 block 的 PHP 类是 Mage_Page_Block_Template_Links
。打开文件 app/code/core/Mage/Page/Block/Template/Links.php
查看 block 的行为方式。并非所有的 block 都有模板文件,但在类定义中它看起来应该是这样的:
class Mage_Page_Block_Template_Links extends Mage_Core_Block_Template
继续往下看,你会看到构造函数中设置了模板文件:
protected function _construct()
{
$this->setTemplate('page/template/links.phtml');
}
所以你要找的模板文件是page/template/links.phtml
。
关于Magento 布局文件模板引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7912473/