22

How do I use a layout xml file to remove an already existing block? Specifically, I want to remove the block named "currency" from the block named "top.switches". It is being inserted in the directory.xml file, like this:

<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>
Benubird
  • 18,551
  • 27
  • 90
  • 141

2 Answers2

39

There are two methods to remove a block defined in one layout xml file, through another xml file:

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

And the way you are conventionally expected to do it:

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

You can find an explanation of the various layout xml elements here, but it doesn't cover the methods available to the action tag. For that, you need to look at the block class app/code/core/Mage/Core/Block/Abstract.php, which features all sorts of useful functions such as unsetChild, unsetCallChild, insert, sortChildren, etc.

Benubird
  • 18,551
  • 27
  • 90
  • 141
8

add file named local.xml in your layout directory . then in local.xml you can remove any block with "remove" tag . BTW the remove tag should be between "layout" and "default" then the file should be :

<?xml version="1.0" encoding="UTF-8"?>
<layout>
   <default>
     <remove name="BLOCK_NAME" />
  </default>
</layout>
Ahmed Samir
  • 81
  • 2
  • 3
  • 1
    @CarComp Magento 1 and 2 are entirely different platforms with very different approaches to the layout XML, so you would be correct. – Navarr Aug 14 '17 at 12:47
  • @CarComp You'd be suprised how much alike M1 and M2 are regarding the remove element: http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/xml-instructions.html – Maarten Wolfsen Nov 20 '17 at 13:24