0

I've created a custom layout xml for a page template and I am trying to remove some blocks that are being added to the page.

I've got template path hints on and have search through the site to find the reference to the .phtml file to find the name of the block and am then trying to remove the block using the below code however the blocks are still appearing on the page?

<referenceBlock name="skip_to_content.target" remove="true"/>
<referenceBlock name="page.main.title" remove="true"/>
<referenceBlock name="messages" remove="true"/>
<referenceBlock name="store_switcher" remove="true"/>

Can anyone please advise how I can remove blocks from the page?

Update:

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_layout.xsd">
    <update handle="empty"/>
    <referenceContainer name="page.wrapper">
        <container name="header.container" as="header_container" label="Page Header Container" before="main.content"/>
        <container name="page.content" as="page_content" label="Page Content" after="header.container"/>
        <container name="footer-container" as="footer" before="before.body.end" label="Page Footer Container"/>
    </referenceContainer>
    <!-- Remove Default -->
    <referenceBlock name="skip_to_content.target" remove="true"/>
    <referenceBlock name="page.main.title" remove="true"/>

    <referenceBlock name="store_switcher" remove="true"/>
    <referenceBlock name="store_switcher" remove="true"/>
    <!-- Shop Home -->        
    <referenceContainer name="page.content">
        <block class="Magento\Framework\View\Element\Template" name="hero" template="Magento_Theme::html/hero.phtml"></block>
        <block class="Magento\Framework\View\Element\Template" name="shop-home-breadcrumbs" template="Magento_Theme::html/shop-home-breadcrumbs.phtml"></block>
        <block class="Magento\Framework\View\Element\Template" name="shop-home-categories" template="Magento_Theme::html/shop-home-categories.phtml"></block>
    </referenceContainer>
</layout>
8
  • Your code is correct can you show all of your layout and check the logs and clear your cache Nov 23, 2017 at 14:58
  • I've updated the code to show my full xml, the code works when inside my default.xml however I need to only remove on this layout?
    – heady12
    Nov 23, 2017 at 15:16
  • Run di:compile then only it will affect
    – Magento 2
    Nov 23, 2017 at 15:19
  • di:compile didn't work :( also tried setup:static-content:deploy but also no affect.
    – heady12
    Nov 23, 2017 at 15:28
  • Not working in the sense any error
    – Magento 2
    Nov 23, 2017 at 15:29

3 Answers 3

1

I've managed to remove the blocks, however I still believe there must be a better way of achieving this:

I updated my default.xml to include:

<!-- Remove Blocks -->
<container name="delete"/>
<referenceContainer name="delete" remove="true" />

And in my custom layout xml I've moved the emails I would like to remove to the delete container:

<!-- Remove Default -->
<move element="skip_to_content.target" destination="delete"/>
<move element="page.main.title" destination="delete"/>
<move element="store_switcher" destination="delete"/>
<move element="messages" destination="delete"/>
3
  • It work for you? Nov 23, 2017 at 15:55
  • Yeah the above is working for me :)
    – heady12
    Nov 23, 2017 at 16:14
  • Ok but its strange i'm sorry for my answer didnt work fine for you have a nice day Nov 23, 2017 at 16:17
0

Try this

    <?xml version="1.0"?>
    <!--
    /**
     * Copyright © 2013-2017 Magento, Inc. All rights reserved.
     * See COPYING.txt for license details.
     */
    -->
    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_layout.xsd">
    <body>

        <referenceContainer name="page.wrapper">
            <container name="header.container" as="header_container" label="Page Header Container" before="main.content"/>
            <container name="page.content" as="page_content" label="Page Content" after="header.container"/>
            <container name="footer-container" as="footer" before="before.body.end" label="Page Footer Container"/>
        </referenceContainer>
        <!-- Remove Default -->
        <referenceBlock name="skip_to_content.target" remove="true"/>
        <referenceBlock name="page.main.title" remove="true"/>

        <referenceBlock name="store_switcher" remove="true"/>
        <!-- Shop Home -->        
        <referenceContainer name="page.content">
            <block class="Magento\Framework\View\Element\Template" name="hero" template="Magento_Theme::html/hero.phtml"></block>
            <block class="Magento\Framework\View\Element\Template" name="shop-home-breadcrumbs" template="Magento_Theme::html/shop-home-breadcrumbs.phtml"></block>
            <block class="Magento\Framework\View\Element\Template" name="shop-home-categories" template="Magento_Theme::html/shop-home-categories.phtml"></block>
        </referenceContainer>

     </body>
    </page>
4
  • Unfortunately this didn't work :/
    – heady12
    Nov 23, 2017 at 15:28
  • I update my post i forgot a body and referenceContainer name="content" Nov 23, 2017 at 15:36
  • Thanks, but unfortunately your updated coding causes my whole page to not load, just get a white blank page. I've managed to get around the issue by creating and removing a 'delete' container and moving the elements to this. ( See my anwser... )
    – heady12
    Nov 23, 2017 at 15:44
  • Can you show me your logs, see my new code Nov 23, 2017 at 15:55
0

Although not directly related to the issue faced detailed in this particular ticket (but still a solution that could be useful to others), I thought it might save someone some time in future if they find custom XML update to not be working correctly..

Within the page_layout/custom-xml.xml file, it's important to include any removes/moves/new containers DIRECTLY within the layout node. Don't use the body node. In my case removing the node caused the XML layout updates to start working.

Example code:

<?xml version="1.0"?>
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_layout.xsd">
<update handle="1column" />
    <!-- Removes -->
    <referenceContainer name="header.container.top" remove="true"/>
    <referenceBlock name="block.name" remove="true"/>

    <!-- New Containers -->
    <referenceContainer name="header.container">
       <container name="new.container" htmlTag="div" htmlClass="new-container-test"/>
    </referenceContainer>
</layout>

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.