0

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?

4

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

  • 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 – gabtzi Dec 20 '18 at 17:48

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.