2

I want to add script tag (google tag manager) right after opening body-tag. I added a referenceContainer to default.xml - but content of "afterbody.phtml" is allways printed AFTER header.container instead of before.

Thanks for help! martin

    <referenceContainer name="after.body.start">
        <block class="Magento\Framework\View\Element\Template" name="afterbody" before="header.container" template="Magento_Theme::afterbody.phtml"/>
    </referenceContainer>
    <referenceContainer name="header.container">
        <container name="header.panel" label="Page Header Panel" htmlTag="div" htmlClass="panel header">
            <block class="Magento\Framework\View\Element\Template" name="skip_to_content" template="Magento_Theme::html/skip.phtml">
                <arguments>
                    <argument name="target" xsi:type="string">contentarea</argument>
                    <argument name="label" translate="true" xsi:type="string">Skip to Content</argument>
                </arguments>
            </block>
            <block class="Magento\Store\Block\Switcher" name="store_language" as="store_language" template="switch/languages.phtml"/>
            <block class="Magento\Framework\View\Element\Html\Links" name="top.links">
                <arguments>
                    <argument name="css_class" xsi:type="string">links</argument>
                </arguments>
            </block>
        </container>
        <referenceBlock name="compare" remove="true" />
        <referenceBlock name="wish-list-link" remove="true" />
    </referenceContainer>
    <referenceContainer name="columns">
        <container name="div.sidebar.main" htmlTag="div" htmlClass="sidebar sidebar-main-1" before="main">
            <container name="sidebar.main" as="sidebar_main" label="Sidebar Main"/>
        </container>
        <container name="div.sidebar.additional" htmlTag="div" htmlClass="sidebar sidebar-additional1" after="div.sidebar.main">
            <container name="sidebar.additional" as="sidebar_additional" label="Sidebar Additional"/>
        </container>
    </referenceContainer>

    <referenceBlock name="top.links">
        <referenceBlock name="register-link" remove="true" />           <!--for Create Account Link-->
        <referenceBlock name="wish-list-link" remove="true" />          <!--for WishList Link-->
        <referenceBlock name="catalog.compare.link" remove="true" /> 
    </referenceBlock>
0

It should not be. Check your layouts for the move instructions and other referenceContainer.

<move element="after.body.start" destination="..." />
...
<move element="header.container" destination="..." />
...
<referenceContainer name="after.body.start" after/before="..." />
...
<referenceContainer name="header.container" after/before="..." />

Link to documentation is http://devdocs.magento.com/guides/v2.1/frontend-dev-guide/layouts/xml-instructions.html

8
  • thanks. i found <referenceContainer name="header.container" remove="true"/> in themeoption layout xml. so i tried to make new name - content is now printed before body end?<referenceContainer name="before.body.start"> <block class="Magento\Framework\View\Element\Template" name="before_body_start" before="page.wrapper" template="Magento_Theme::afterbody.phtml"/> </referenceContainer>
    – matin
    Aug 30 '17 at 7:07
  • Hmm.. no :) The location of the block/container does not depend of its name. Line <referenceContainer name="header.container" remove="true"/> must to removed header.container from page. This block is printed now? Aug 30 '17 at 9:06
  • the header.container is not printed. my new container is printed on the wrong place - it should be right after opening body-tag, but is printed after page-wrapper <referenceContainer name="before.body.start"> <block class="Magento\Framework\View\Element\Template" name="before_body_start" before="page.wrapper" template="Magento_Theme::afterbody.phtml"/> </referenceContainer>
    – matin
    Aug 30 '17 at 12:55
  • Try this: <referenceContainer name="root"><block class="Magento\Framework\View\Element\Template" template="Magento_Theme::afterbody.phtml" before="-" /></referenceContainer> It works for me - block display right after opening body Aug 30 '17 at 13:46
  • thanks! Try this: <referenceContainer name="root"><block class="Magento\Framework\View\Element\Template" template="Magento_Theme::afterbody.phtml" before="-" /></referenceContainer> It works for me - block display right after opening body is working!!!!
    – matin
    Aug 30 '17 at 13:51
0

Try this: <referenceContainer name="root"><block class="Magento\Framework\View\Element\Template" template="Magento_Theme::afterbody.phtml" before="-" /></referenceContainer> It works for me - block display right after opening body

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.