我研究过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>
Run Code Online (Sandbox Code Playgroud)
所以我在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>
Run Code Online (Sandbox Code Playgroud)
它告诉我们,标题块中有一个top.links块
小智 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
Run Code Online (Sandbox Code Playgroud)
继续阅读,您将看到模板文件在构造函数中设置:
protected function _construct()
{
$this->setTemplate('page/template/links.phtml');
}
Run Code Online (Sandbox Code Playgroud)
所以你要找的模板文件是page/template/links.phtml.