什么阻止我的布局更新显示

时间:2014-01-30 17:14:44

标签: magento

我正在尝试使用我创建的特殊块在Magento网站上显示一条简单的消息。我已经能够轻松地取消设置块并将它们插入主页上的其他位置,但是当我尝试在其中一个产品页面上执行相同操作时遇到了麻烦。我在app / design / frontend / base / default / layout / packagename / modulename.xml创建了一个文件 具有以下内容:

<?xml version="1.0"?>
<layout>
    <default>
        <reference name="product.info">
            <block type="core/text" name="free_shipping">
                <action method="setText"><text><![CDATA[<div>Free Shipping!</div>]]>            </text></action>
            </block>
        </reference>

        <reference name="header">
            <action method="unsetChild">
                <name>top.search</name>
            </action>
        </reference>

    </default>
</layout>

在我看来,上面的代码会从产品页面中删除搜索栏,并在产品信息部分添加一个块,上面写着“免费送货!”但是当我加载页面时没有任何变化。我已经尝试使用“删除”来改变页面上的一些块并且它可以工作,因此该文件肯定被加载到layout.xml中。我也尝试在local.xml文件中进行更改,但结果相同。除此之外,我有点不知所措,试图让它正常工作。

编辑:要提供有关此问题的更多信息,如果我要用

等替换我的更改
<reference name="root">
    <action method="unsetChild">
        <name>header</name>
    </action>
</reference>

标头已成功删除。所以我想现在的问题是,为什么在“根”块上使用而不是在“标题”上调用未设置的子项按预期工作?

2 个答案:

答案 0 :(得分:0)

我认为您需要更具体地使用布局处理程序,您将其设置为,这意味着所有页面,我建议您通过

更改该处理程序
<?xml version="1.0"?>
<layout>
    <catalog_product_view>
        <reference name="product.info">
            <block type="core/text" name="free_shipping">
                <action method="setText"><text><![CDATA[<div>Free Shipping!</div>]]>                </text></action>
            </block>
        </reference>

        <reference name="product.info">
            <block name="header">
                <action method="unsetChild">
                    <name>top.search</name>
                </action>
            </block>
        </reference>
    </catalog_product_view>
</layout>

问候。

答案 1 :(得分:0)

首先,永远不要把你的东西放在base / default文件夹中。

关于你的问题。如果你这样尝试怎么办:

<reference name="header">
    <action method="unsetChild">
        <name>top.search</name>
    </action>
</reference>

回答你的另一个问题:

  

标头已成功删除。所以我想现在的问题是,为什么在“根”块上使用而不是在“标题”上调用未设置的子项按预期工作?

这不是它在根块上的事实,而是你应该在<reference/>部分使用unsetChild。

相关问题