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>
Firstly you need to create layout file for the same controller. in this, you can use referenceBlock for the blocks, and referenceContainer for the containers. name, is the name of the block or container which you want to remove. remove, is set to true to remove.
For moving a block to another destination, we need to use the <move> tag with a specific element name and destination place. <move> Tag will set the declared block or container element as a child of another element in the specified order.
Except for displaying CMS block on CMS Page or CMS Block, showing it on category page there is an option to call CMS block programmatically using XML file. You need to replace "my_cmsblock_identifier" with your CMS block Identifier or ID (we recommend to use Identifier).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With