Ben*_*ird 21 xml layout magento
如何使用布局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>
Ben*_*ird 37
有两种方法可以通过另一个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元素的说明,但不包括action标记可用的方法.为此,您需要查看块类app/code/core/Mage/Core/Block/Abstract.php,它具有各种有用的功能,如unsetChild,unsetCallChild,insert,sortChildren等.
小智 8
在布局目录中添加名为local.xml的文件.然后在local.xml中,您可以删除任何带有"remove"标记的块.BTW删除标签应该在"布局"和"默认"之间,那么文件应该是:
<?xml version="1.0" encoding="UTF-8"?>
<layout>
   <default>
     <remove name="BLOCK_NAME" />
  </default>
</layout>