How can I remove an argument's item in Magento's LyoutXML?

For instance I would like to remove <item name="msrp_price" xsi:type="array"> from catalog_product_prices.xml.

In my theme's catalog_product_prices.xml, I've tried using remove="true" (see below), but it doesn't work, any ideas on how I can achieve this?

<?xml version="1.0"?>
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
    <referenceBlock name="render.product.prices">
            <argument name="default" xsi:type="array">
                <item name="prices" xsi:type="array">
                    <item name="msrp_price" xsi:type="array" remove="true">
                        <item name="render_class" xsi:type="string">Magento\Msrp\Pricing\Render\PriceBox</item>
                        <item name="render_template" xsi:type="string">Magento_Msrp::product/price/msrp.phtml</item>
  • You could use the _prepareLayout() method in the block lifecycle. Arguments are set in the $data property of the block. You need to extend and override the block with di for this. – vitoriodachef Jun 21 '19 at 11:06

The two ideas I have for solving this are as follows:

Overriding with an empty item

My first attempt would be to override the item with nothing effectively emptying it.

<item name="msrp_price" xsi:type="array"></item>

Full block override

I don't like the idea of this one but as a last resort it will work, and that is to fully override the block such as removing the core block and re-creating it without msrp_price. As you're creating the block you have full control over what is contained within it, but this method will result in duplicated code and potentially cause issues with patches/updates.

Slightly related post here - Magento 2 - How to reset XML block arguments such as CSS

| improve this answer | |
  • Thanks, that's helpful. The first approach did not work though, and I also don't like the 2nd approach as it removed the extensibility of the original block which a lot of Magento Modules touch – Holly Apr 26 '19 at 9:53
  • Damn it, what about emptying the child items like so: <item name="render_class" xsi:type="string"></item> <item name="render_template" xsi:type="string"></item> – Ben Crook Apr 26 '19 at 9:59
  • yep, tried that too. It just renders it as normal – Holly Apr 26 '19 at 10:33
  • How did you managed to removed the argument in XML ? I am also facing the same situation.. – aravind Jan 21 at 5:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.