Magento-使用更新XML删除块
如何使用布局xml文件删除已存在的块?具体来说,我想从名为“top.switches”的块中删除名为“currency”的块。它被插入到directory.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
<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>