2

I have created a cms block and using widget added inside header page container, now I want to remove that block from only home page.

How can i achieve this?

Widget screenshot to display block

enter image description here

0

From Layout file:

Goto app/design/frontend/[VendorTheme]/[ThemeName]/Magento_Cms/layout/cms_index_index.xml and add below code. BlockName will be the name of block which you want to delete.

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
  <body>
   <!-- add this code for remove block -->
   <referenceBlock name="BlockName" remove="true"/>
 </body>
 </page>
  • I implement this but not working – Arjun Mar 27 at 8:43
0

Into the CMS home page, Design -> Layout Update XML

<referenceBlock name="BlockName" remove="true"/>

save the cms page and clear the cache.

without xml you want to hide them using css display none.

  • i get following error 'Please correct the XML data and try again. Element 'referenceBlock': This element is not expected. Expected is one of ( referenceContainer, container, update, move, head, body ). Line: 1' – Arjun Mar 27 at 8:35
0

create below file

app/design/frontend/name/example/Magento_CMS/layout/cms_index_index.xml

<referenceBlock name="block_name" remove="true"/>

add below code and add your static block_name Example:

<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="block_name" remove="true"/>
    </body>
</page>
  • I implement this but not working – Arjun Mar 27 at 8:43
0

It would be best if you put the following code:

<referenceBlock name="block_name" remove="true"/>

in the Design >> Layout Update XML section of your CMS Home page in the admin panel.

After that, you just need to flush Magento's cache.

Since Magento provides to update the layout of CMS pages from the backend, there is no need to do it using the layout files.

Update: widget xml generated on save widget

I hope it is clear.

  • i get following error 'Please correct the XML data and try again. Element 'referenceBlock': This element is not expected. Expected is one of ( referenceContainer, container, update, move, head, body ). Line: 1' – Arjun Mar 27 at 8:33
  • Also, If i add block id in name will it work – Arjun Mar 27 at 8:35
  • @Arjun, you are right. I noticed your point now. This is happening because while adding a widget to the pages, Magento generates the block name dynamically. – Mohit Kumar Arora Mar 27 at 11:37
  • When we try to print the generated XML after saving the widget instance, we get the block name as a random string. Please check the screenshot in my answer's update. – Mohit Kumar Arora Mar 27 at 11:59
  • ok i got your point so what do you suggest how can i remove this block only on home page or else i should remove widget – Arjun Mar 27 at 12:13

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.