Magento 2 Add custom class before “main.content” excluding Home Page
-
13-03-2021 - |
Question
I am looking for a solution to add a custom class before "main.content" for all pages remaining home page. Currently, I am doing below code
<referenceContainer name="page.wrapper">
<container name="your.custom.name" as="your-custom" label="Your Label Name" htmlTag="div" htmlClass="custom_class" htmlId="your-id" before="page-footer"/>
</referenceContainer>
<move element="main.content" destination="your.custom.name"/>
in default.xml.
but this code adding "custom_class" class for all pages. I want to exclude from the home page. Please suggest if anyone has an idea.
Solution
Remove your.custom.name
container from the cms_index_index.xml
file placed under Magento_Theme/layout/cms_index_index.xml
with below content.
<referenceContainer name="your.custom.name" remove="1" />
Edit:
Add below content in Magento_Theme/layout/cms_index_index.xml
file.
<referenceContainer name="page.wrapper">
<container name="your.custom.name" as="your-custom" htmlTag="div" before="page-footer"/>
</referenceContainer>
<move element="main.content" destination="your.custom.name"/>
Hope this helps!!!
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange