在Magento中,能否仅通过xml将静态块添加到标头?
我试图在可能的情况下仅使用local.xml定制主题.我想在不修改header.phtml的情况下将静态块添加到头.这段代码适用于内容区域,但不适用于标题:
I am trying to customize a theme using only local.xml whenever possible. I want to add a static block to the header without modifying header.phtml. This code works fine for the content area, but not for the header:
<default>
<reference name="content">
<block type="cms/block" name="how-it-works-button">
<action method="setBlockId"><block_id>how-it-works</block_id></action>
</block>
</reference>
</default>
有人知道为什么吗?我以为我需要做的就是将内容"更改为标题",但是当我这样做时却什么也没显示.
Anybody know why? I thought that all I would need is to change "content" to "header", but nothing shows up when I do.
感谢您的帮助!
content
块是一个特殊的块,称为core/text_list
块(PHP类Mage_Core_Block_Text_List
).这些块将自动呈现添加到它们的所有子块.
The content
block is a special block known as a core/text_list
block (PHP class Mage_Core_Block_Text_List
). These blocks will automatically render out any child blocks that are added to them.
header
块是page/html_header
块(PHP类Mage_Page_Block_Html_Header
).该块类继承自Mage_Core_Block_Template
,使其成为core/template
块.如果模板块的相应phtml
模板请求子块,则模板块将仅渲染子块.因此,通过将块添加到标头中,您只需完成一半的工作即可. 您需要创建一个自定义的phtml
模板.
The header
block, on the other hand, is a page/html_header
block (PHP class Mage_Page_Block_Html_Header
). This block class inherits from Mage_Core_Block_Template
, making it a core/template
block. Template blocks will only render sub-blocks if their corresponding phtml
template requests the block. So, by adding your block to the header, you're only doing half the work you need to. You'll need to create a custom phtml
template.
最简单的方法(发布1.4.1.1
是根据您自己的主题,在以下位置创建文件
The simplest way to do this (post 1.4.1.1
is to, in your own theme, create a file at
template/page/html/header.phtml
然后在此文件末尾添加
<?php echo $this->getChildHtml('how-it-works-button'); ?>
假设您已通过布局xml向标头块添加了一个块,这应该呈现您的模板.
Assuming you've added a block to header block via layout xml, this should render your template.