6

I'm trying to get a block to embed on all pages. I've tried many references containers including footer, page.top and page.wrapper. The only one I've managed to get to include correctly on the thankyou (order success) page in footer.

Even using footer the embed does not seem to happen on category or CMS pages. I'm using the default Magento 2 theme and test data.

My default.xml is as follows:

<?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">
    <head> </head>
    <body>
        <referenceContainer name="footer">
            <block class="Company\Module\Block\Module" name="company_module" template="Company_Module::tracking.phtml" />
        </referenceContainer>
    </body>
</page>

Any ideas appreciated.

1
  • How about your issue? I updated my answer. Oct 15, 2016 at 6:30

2 Answers 2

6

The footer and header are removed in the checkout page. So, when we try to reference these blocks, our block will be removed also.
We can follow the logic of the copyright. Try to move your element outside the footer - <move element="company_module" destination="before.body.end"/>.

<?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">
        <block class='Company\Module\Block\Module' name="company_module" as="company_module" template="Company_Module::tracking.phtml"/>
        </referenceContainer>
    <move element="company_module" destination="before.body.end"/>
    </body>
</page>

Or we can reference to before.body.end or after.body.start container:

<?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="before.body.end">
        <block class='Company\Module\Block\Module' name="company_module" as="company_module" after="footer_links" template="Company_Module::tracking.phtml"/>
     </referenceContainer>
     <!--<referenceContainer name="after.body.start">-->
        <!--<block class='Company\Module\Block\Module' name="company_module" as="company_module" after="footer_links" template="Company_Module::tracking.phtml"/>-->
    <!--</referenceContainer>-->
   </body>
</page>
4
  • Thanks. I tried both, but neither actually worked to get my template embedded in category pages. By category page I mean those pages such as magento2.dev/women/tops-women.html in the sample data. Oct 10, 2016 at 20:34
  • You're using a custom theme? All the footer content will miss in the category page? I'm pretty sure that if we reference to before.body.end container, our block still show. Please, check again. Oct 11, 2016 at 16:19
  • Sadly, no it's not a custom theme. This is the default theme that comes with the "sample data" Magento 2.0 CC. Neither setting "before.body.end", nor trying the move operator seems to work. I'm sure I must be missing some kind of caching or such problems ... Oct 17, 2016 at 20:44
  • I've been looking at this problem again. Any help? This is the default theme, LUMA. Won't show on category pages with "footer" or "before.body.end". :( Sep 12, 2017 at 23:45
3

You can try this code, working fine for me

<?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">
    <block class="Vendor\Module\Block\Test\Test" after="footer_links" template="Vendor_Module::test/test.phtml"/>
        </referenceContainer>
    </body>
</page>
1
  • Thanks, although I have tried the direct footer as you suggest and there are pages missing. Oct 10, 2016 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.