2

how can I add a custom block to the footer. I want to add a new block with new links next to the existing block with the contact links etc and show them beside the default block of the Luma template.

Thanks.

2
  • In Magento 2.0 ?
    – Sohel Rana
    Dec 21, 2015 at 10:04
  • Yes in Magento 2.0.
    – ClassMP
    Dec 21, 2015 at 10:15

3 Answers 3

3

I solved it now by creating a new block in the reference of the footer container of my module default.xml.

<referenceContainer name="footer-container">
    <container name="footer" as="footer" label="Page Footer" htmlTag="div" htmlClass="footer content">

        <block class="Magento\Framework\View\Element\Html\Links" name="footer_company_links">
            <arguments>
                <argument name="css_class" xsi:type="string">footer links</argument>
            </arguments>
        </block>

        <block class="Magento\Framework\View\Element\Html\Links" name="footer_links" after="footer_company_links">
            <arguments>
                <argument name="css_class" xsi:type="string">footer links</argument>
            </arguments>
        </block>    

        <block class="Magento\Theme\Block\Html\Footer" name="copyright" template="html/copyright.phtml"/>

    </container>
</referenceContainer>
1
  • 2
    Weird, all this did was remove the footer entirely for me. Apr 11, 2019 at 17:40
1

create default.xml in [Vendor]/[ModuleName]/view/frontend/layout/ and add below code

<?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>
        <referenceBlock name="footer_links">
            <block class="Magento\Framework\View\Element\Html\Link\Current" name="2custom-link">
                <arguments>
                    <argument name="label" xsi:type="string">Custom Links</argument>
                    <argument name="path" xsi:type="string">page-url</argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>
</page>

finally flush cache and run it. If you have own block then define class name as your block name.

1
  • Thanks for your answer. But I'm looking for a code to add a new block with new links next to the existing block with the contact links etc.
    – ClassMP
    Dec 21, 2015 at 10:21
1

call custom block and links in footer in magento 2

In this article we will learn how to call links and custom block in footer in magento 2.

So, the file which is used to define configurations of footer is default.xml. This file will be located under app/code/Namespace/Module/view/frontend/layout/. This file calls on every page, that’s why we write code for footer in this file.

Below code is used to call custom links in footer :

Custom Link path/to/page

Now If you want to add your own custom block and template inside the footer, then below code will be used :

<referenceContainer name="footer-container">
  <block class="Magento\Theme\Block\Html\Footer" name="custom_block" as="custom_block" template="custom.phtml"/>
</referenceContainer>

That’s all in this article, hope it will help you to call custom block and links inside footer. Try the above code and if you have any issue just comment below. 🙂

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.