Magento2 – Fix New Container Not Showing

containersmagento2

I'm trying to add a new container to a layout (extending Magento Blank) but it's not rendering in HTML. I added the following to:

app/design/frontend/VENDOR/MYTHEME/Magento_Theme/layout/default.xml

<container name="mike.container" as="mikeContainer" label="Mike Container" htmlTag="div" htmlClass="mike-container" />

I cleaned the cache and refreshed the page and then looked at the source code rendered by my browser but a div with a class of "mike-container" doesn't exist.

Do I need to do something else?

Thank you

Best Answer

David's answer is correct, but his example doesn't work (for me anyway).

If you swap the text block in his example with a template block you'll see the container then displays.

My full example to get it working:

app/design/frontend/PACKAGE/THEME/Magento_Cms/layout/default.xml

<?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="footer">
            <container name="mike.container" as="mikeContainer" label="Mike Container" htmlTag="div" htmlClass="mike-container">
                <block class="Magento\Framework\View\Element\Template" name="testing" template="Magento_Cms::test.phtml" />
            </container>
        </referenceContainer>
    </body>
</page>

app/design/frontend/PACKAGE/THEME/Magento_Cms/templates/test.phtml

<h2>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatem suscipit, adipisci, cum quos, alias similique ad eum at deserunt eligendi enim dignissimos, unde vero ipsam voluptatibus cumque accusantium! Obcaecati, quasi.</h2>

Result

enter image description here

If I remove the template block, the container is no longer rendered.

Related Topic