1

I'm trying to add a new container into root. I've tried placing the code to empty.xml, default.xml, 1column.xml. I've checked with changing another element in the same file if the file is loaded and parsed. But whatever I do I just can't add the container. This is the code:

<referenceContainer name="root">
    <referenceContainer name="header.container" htmlId="header"/>
    <container name="header.container.mobile" as="header_container_mobile" label="Page Mobile Header Container" htmlTag="header" htmlId="header_mobile" htmlClass="navbar navbar-fixed-top" after="header.container"/>
</referenceContainer>

So it will add the html id "header" to the "header.container" which appears as <header ...> in the page. (I have moved this container to root elsewhere). But it doesn't add the container "header.container.mobile". (I have tried other names too)

How can I add the container?

  • I can't even add it into the core files. If I place it just right below the instantiation of header.container in the core file of Magento_Theme htdocs/vendor/magento/module-theme/view/frontend/page_layout/1column.xml it still does not appear, even though adding another class to the footer in the same file does appear... – steros Dec 20 '16 at 8:50
2

I'm reasonably sure a container needs some contents before it'll show up.

  • No, it shows up without anything in it, which is odd but i guess its just generating an element on the page no matter what. – andy jones Dec 20 '16 at 9:00
  • Odd. I've always had to add something to get it to show up. – Eamonn Dec 20 '16 at 9:03
  • Maybe depends on the version? 2.0.1 vs 2.0.0 vs 2.1.2 ?? Not sure but seems to render without anything in it for me >_< – andy jones Dec 20 '16 at 9:05
  • It doesn't render without content for me too. Boy what a headache. After adding a block into the container it shows up. I mean its a, what I call real, container defining itself with an html tag. Why wouldn't it show up without content? – steros Dec 20 '16 at 9:08
  • Must be a 2.1 thing as that's what I've been using. – Eamonn Dec 20 '16 at 9:14
3

Im pretty sure you don't need to do it into 'root' how you have done it.

I would think it is like so.

<referenceContainer name="page.wrapper">
    <container name="some.container" as="someContainer" label="Some Container" htmlTag="div" htmlClass="some-container" after="header.container" />
</referenceContainer>

Add this into:

Vender/theme/Magento_Theme/layout/default.xml

Or for root it might be:

<container name="root">
        <container name="some.container" as="someContainer" label="Some Container" htmlTag="div" htmlClass="some-container" after="header.container" />
    </container>
  • This doesn't work and if it did I'm pretty sure it would add "header_mobile" into "header.container". But I want the new container below "header.container". – steros Dec 20 '16 at 8:43
  • I misread what you put, that should now add a container after the header.container. – andy jones Dec 20 '16 at 8:50
  • Sorry to bother you but I have moved header.container to the root container, it is not in the page.wrapper anymore at that point. – steros Dec 20 '16 at 8:54
  • Okay this is a bit of a guess, as i've not done that yet haha. Instead of using referencecontainer use <container name="root"> and drop the new container into that. – andy jones Dec 20 '16 at 9:00

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.