I am trying to add my custom div with class and id before the maincontent.
<main id="maincontent" class="page-main">
can i add the custom div before this line? How this can be done. Please anyone suggest me.
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityYou can try the below code:
<referenceContainer name="page.wrapper">
<container name="your.custom.name" as="your-custom" label="Your Label Name" htmlTag="div" htmlClass="your-class" htmlId="your-id" before="main.content">
<block class="Magento\Framework\View\Element\Template" name="custom.file" template="Vendor_Module::custom.phtml" /><!-- This is just an example -->
</container>
</referenceContainer>
UPDATED ANSWER AS PER COMMENT:
Create default.xml under:
app/design/frontend/Vendor/theme/Magento_Theme/layout/default.xml
<referenceContainer name="page.wrapper">
<container name="your.custom.name" as="your-custom" label="Your Label Name" htmlTag="div" htmlClass="your-class" htmlId="your-id" before="page-footer"/>
</referenceContainer>
<move element="main.content" destination="your.custom.name"/>
You can use below code:
<?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.wrapper">
<container name="custom_container" as="custom_container" label="Custom Container" htmlTag="div" htmlClass="your_class" after="main.content">
<block class="Magento\Framework\View\Element\Text" name="comment.placeholder">
<arguments>
<argument name="text" xsi:type="string"><![CDATA[<!-- Lorem Ipsum -->]]></argument>
</arguments>
</block>
</container>
</referenceContainer>
</body>
</page>
In the custom container, you must put something for rendering the container div
.