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>
  • Your code is correct can you show all of your layout and check the logs and clear your cache – Mohamed El Mrabet Nov 23 '17 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 '17 at 15:16
  • Run di:compile then only it will affect – Magento 2 Nov 23 '17 at 15:19
  • di:compile didn't work :( also tried setup:static-content:deploy but also no affect. – heady12 Nov 23 '17 at 15:28
  • Not working in the sense any error – Magento 2 Nov 23 '17 at 15:29
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"/>
  • It work for you? – Mohamed El Mrabet Nov 23 '17 at 15:55
  • Yeah the above is working for me :) – heady12 Nov 23 '17 at 16:14
  • Ok but its strange i'm sorry for my answer didnt work fine for you have a nice day – Mohamed El Mrabet Nov 23 '17 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>
  • Unfortunately this didn't work :/ – heady12 Nov 23 '17 at 15:28
  • I update my post i forgot a body and referenceContainer name="content" – Mohamed El Mrabet Nov 23 '17 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 '17 at 15:44
  • Can you show me your logs, see my new code – Mohamed El Mrabet Nov 23 '17 at 15:55

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.