2

I added div(container) in every page except homepage like this

<main>
        <div class="myclass">
              all content here
        </div>
    </main>

I tried update layout from admin and cms_index_index.xml file by using remove tag but doesn't work for me. I only need to remove that container class or div not all child blocks & containers

Let's consider my container in my empty.xml (override).

<container name="container_name" htmlClass="myclass" htmlTag="div"/>

It's come as I want but I don't want it on homepage

How can I remove that container from homepage.

  • I hope my answer will resolve your issue. – Nikunj Vadariya Jun 12 '18 at 13:29
  • @NikunjVadariya any alternative solution for add div using container in all pages except homepage ? – lalit mohan Jun 12 '18 at 13:33
  • first you need to add it for all page and then remove it for the home page as i describe in my updated answer. it is the sort and good way to solve your issue thanks. – Nikunj Vadariya Jun 12 '18 at 13:36
0

You can do it using two ways:

using xml file and add code in admin let me describe both solution.

solution 1: Create XML file

Create cms_index_index.xml file

add code

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
  <body>
      <referenceContainer name="container_name" remove="true"/>
</body>
</page>

Solution 2: add same code from admin side

Go to your admin panel > open cms home page. There is a one tab DESIGN and in this tab add your xml code in Layout Update XML area. enter image description here

Both are working as per your requirement.(y)

  • sorry I forgot to mention what I tried I already tried this . I need to remove my that div /class not all container . it remove all containter child containers and blocks also – lalit mohan Jun 12 '18 at 13:22
0

If you want to declare block for magento theme.

Place block declaration into the

Magento_Theme/layout/cms_index_index.xml

file.

for magento module

place block declaration into the

app/code/yourmodule_namespace/your_module/view/frontend/layout

ex:

<?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>
  <referenceContainer name="page.top"> 
        <container name="banner" as="banner" label="Banner"   htmlTag="div" htmlClass="banner" htmlId="banner">
            <block class="Magestore\Bannerslider\Block\Bannerslider" name="bannerslider.content.top" before="-" />
       </container>      
</referenceContainer>    

You can refer this blog for better understanding.

  • I already have that cms_index_index.xml I know very well. I need to remove only class not child containers & blocks within that container – lalit mohan Jun 12 '18 at 13:23
0

You can remove class by this way:

Go to your admin panel > cms home page. There is one tab DESIGN and in this tab add your XML code in Layout Update XML area.

<referenceContainer name="container_name" htmlClass="">

Keep empty so it will remove the class.

Run command:

php bin/magento cache:flush

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.