Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento - remove block using update XML

Tags:

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> 
like image 593
Benubird Avatar asked Jun 05 '13 10:06

Benubird


People also ask

How do I delete a block in Magento?

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.

How do I move a block in XML in Magento 2?

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.

How do you call a CMS block in XML file in Magento 2?

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).


1 Answers

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.

like image 78
Benubird Avatar answered Oct 06 '22 23:10

Benubird