1

I'm trying to create a container inside page.wrapper to contain some custom blocks for my checkout page.

When I try the following in

app/design/frontend/MyTheme/myname/Magento_Theme/layout/checkout_index_index.xml

<body>
 <referenceContainer name="logo-container">
 <referenceBlock name="onestepcheckout-logo" remove="true" />
 </referenceContainer>
 <referenceContainer name="page.wrapper">
 <container name="footer-custom3" as="footer" after="main.content" label="Page Footer Container" htmlTag="footer" htmlClass="page-footer" >
 </container>
 </referenceContainer>
</body>

I get an error that

Exception #0 (Magento\Framework\Exception\LocalizedException): The 'footer-custom3' is not a child of 'page.wrapper'.

How do I make it a child of page.wrapper?

Also if I use it as a child of main.content as in the following it shows up

<referenceContainer name="main.content">
 <container name="footer-custom3" as="footer" after="main.content" label="Page Footer Container" htmlTag="footer" htmlClass="page-footer" >
 <block class="CleverSoft\Base\Block\Template" name="footer_block" template="html/footer.phtml">
 <block class="Magento\Store\Block\Switcher" name="footer.store_switcher" template="switch/stores.phtml" />
 <block class="Magento\Newsletter\Block\Subscribe" name="footer.newsletter" template="subscribe_footer.phtml" />
 </block>
 </container>
</referenceContainer>

Could someone explain to me why this is not working for page.wrapper?

Abhishek Panchal
4,9643 gold badges22 silver badges39 bronze badges
asked Dec 20, 2018 at 14:49

1 Answer 1

5

It's because of page.wrapper already has had a container with an alias is footer:

<referenceContainer name="page.wrapper">
 <container name="header.container" as="header_container" label="Page Header Container" htmlTag="header" htmlClass="page-header" before="main.content"/>
 <container name="page.top" as="page_top" label="After Page Header" after="header.container"/>
 <container name="footer-container" as="footer" before="before.body.end" label="Page Footer Container" htmlTag="footer" htmlClass="page-footer"/>
</referenceContainer>

When you try to add a container with the same alias footer, it is not added into list children of page.wrapper, it means when layout call getChildOffSet('footer') this will return footer-container instead of footer-custom3

You can read more detail in \Magento\Framework\Data\Structure::_getChildOffset and you can see the index of this

$index = array_search($childId, array_keys($this->getChildren($parentId)));

will be return false with $childId='footer-custom3'

I suggest you should change the alias to something else like as="footer-3" or your should remove footer-container before adding footer-custom3

<referenceContainer name="footer-container" remove="true"/>

If you see my answer is useful, please give me a vote

Thanks

Ashish Viradiya
1,5802 gold badges20 silver badges39 bronze badges
answered Dec 20, 2018 at 15:18
1
  • Nice, thanks for the detailed explanation. The error message was confusing me. I was thinking maybe I was missing something similar to magento 1 where you had to also echo $this->getChildHtml('block_name') in some cases but it was much simpler. Much appreciated Commented Dec 20, 2018 at 17:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.