【问题标题】:Magento - remove block using update XMLMagento - 使用更新 XML 删除块
【发布时间】:2013-05-31 23:33:20
【问题描述】:

如何使用布局 xml 文件来删除已经存在的块?具体来说,我想从名为“top.switches”的块中删除名为“currency”的块。它被插入到 directory.xml 文件中,如下所示:

<default>
    <reference name="top.switches">
        <block type="directory/currency" name="currency" before="store_language" template="directory/currency.phtml"/>
    </reference>
    <reference name="head">
        <block type="core/template" name="optional_zip_countries" as="optional_zip_countries" template="directory/js/optional_zip_countries.phtml" />
    </reference>
</default>

【问题讨论】:

    标签: xml magento layout


    【解决方案1】:

    有两种方法可以删除一个布局xml文件中定义的块,通过另一个xml文件:

    <default>
        <reference name="top.switches">
            <action method="unsetChild"><name>currency</name></action>
        </reference>
    </default>
    

    以及您通常期望的方式:

    <default>
        <reference name="top.switches">
            <remove name="currency" />
        </reference>
    </default>
    

    您可以找到对各种布局 xml 元素 here 的解释,但它不包括可用于操作标记的方法。为此,您需要查看块类 app/code/core/Mage/Core/Block/Abstract.php,其中包含各种有用的功能,例如 unsetChild、unsetCallChild、insert、sortChildren 等。

    【讨论】:

      【解决方案2】:

      在布局目录中添加名为 local.xml 的文件。然后在 local.xml 中,您可以使用“remove”标签删除任何块。顺便说一句,删除标签应该在“布局”和“默认”之间 那么文件应该是:

      <?xml version="1.0" encoding="UTF-8"?>
      <layout>
         <default>
           <remove name="BLOCK_NAME" />
        </default>
      </layout>
      

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-11
      • 2016-09-12
      • 1970-01-01
      • 2015-03-27
      • 2012-09-11
      • 2014-03-25
      • 2012-09-07
      相关资源
      最近更新 更多