Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento-使用更新XML删除块_Xml_Magento_Layout - Fatal编程技术网

Magento-使用更新XML删除块

Magento-使用更新XML删除块,xml,magento,layout,Xml,Magento,Layout,如何使用布局xml文件删除已存在的块?具体来说,我想从名为“top.switches”的块中删除名为“currency”的块。它被插入到directory.xml文件中,如下所示: <default> <reference name="top.switches"> <block type="directory/currency" name="currency" before="store_language" template="directo

如何使用布局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文件删除一个布局xml文件中定义的块:

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


,但它不包括action标记可用的方法。为此,您需要查看块类app/code/core/Mage/core/block/Abstract.php,它具有各种有用的函数,如unsetChild、unsetCallChild、insert、sortChildren等。

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

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


@CarComp Magento 1和2是完全不同的平台,对布局XML的处理方法非常不同,因此您是正确的。@CarComp您会惊讶于M1和M2在删除元素方面有多么相似:
<?xml version="1.0" encoding="UTF-8"?>
<layout>
   <default>
     <remove name="BLOCK_NAME" />
  </default>
</layout>