在Magento中,能否仅通过xml将静态块添加到标头? [英] In Magento, can I add a static block to the header by xml only?

查看:78
本文介绍了在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.

这篇关于在Magento中,能否仅通过xml将静态块添加到标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆