如何使用布局 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>
以及通常期望您这样做的方式:
<default>
<reference name="top.switches">
<remove name="currency" />
</reference>
</default>
您可以找到各种布局 xml 元素的说明here http://magebase.com/magento-tutorials/demystifying-magentos-layout-xml-part-1/,但它不涵盖操作标记可用的方法。为此,您需要查看块类 app/code/core/Mage/Core/Block/Abstract.php,它具有各种有用的函数,例如 unsetChild、unsetCallChild、insert、sortChildren 等。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)