Magento – Magento 2 – Add a new container

layoutlayout-updatemagento2xml

I'm trying to add a new container according to the Magento 2 documentation, but it isn't working. Here is what I'm trying:

<container name="some.container" as="someContainer" label="Some Container" htmlTag="div" htmlClass="some-container" />

I'm not seeing the markup anywhere after I refresh. Caching is off too.

Best Answer

Use the following code to add a new container in Magento 2:

<referenceContainer name="columns.top">
<container name="custom-content" as="custom-content" label="Page Custom
Content" htmlTag="div" htmlClass="custom-content">
<block class="Magento\Framework\View\Element\Template"
name="custom-content" template="Magento_Theme::html/custom-content.phtml" />
</container>
</referenceContainer>

Insert the above code in default.xml, path below:

path: /app/design/frontend/spacename/Theme/Magento_Theme/layout/default.xml

Create a file custom-content.phtml inside: path :

/app/design/frontend/spacename/Theme/Magento_Theme/template/html/custom-content.phtml