Magento – Magento 2: Adding a new block to a child theme

layoutmagento2parent-child-themetemplatexml

Just getting to grips with Magento 2.. I have created and applied a child theme of Luma that seems to work fine. It pulls in my CSS files and things like that. But I would like to add some custom blocks to the footer.

Here are the contents of my default.xml which is in mytheme/Magento_Theme/layout/default.xml

As you can see I've tried to create a new block called footer_social, I have then created a .phtml file which sits in mtheme/Magento_Theme/html/footer_social.phtml and added a little bit of text to it to test but nothing changes. Guessing I am missing something? Any help appreciated.

    <?xml version="1.0"?>
<!--
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="header.panel">
            <block class="Magento\Framework\View\Element\Html\Links" name="header.links">
                <arguments>
                    <argument name="css_class" xsi:type="string">header links</argument>
                </arguments>
            </block>
        </referenceContainer>
        <referenceBlock name="logo">
            <arguments>
                <argument name="logo_img_width" xsi:type="number">148</argument>
                <argument name="logo_img_height" xsi:type="number">43</argument>
            </arguments>
        </referenceBlock>
        <referenceContainer name="footer">
            <block class="Magento\Store\Block\Switcher" name="store_switcher" as="store_switcher" after="footer_links" template="switch/stores.phtml"/>
            <block class="Magento\Framework\View\Element\Template" name="footer_social" template="Magento_Theme::html/footer_social.phtml">
        </referenceContainer>
        <referenceBlock name="report.bugs" remove="true"/>
        <move element="copyright" destination="before.body.end"/>
    </body>
</page>

Best Answer

since the store switcher is already added in the luma theme, you should not add it again in your theme to the footer (to be honest I'm not 100% sure if it gets overridden or maybe cause an error when you add a block with the same name)

For your issue, I think it's just an xml fault. You did not close the block tag correctly https://stackoverflow.com/questions/7231902/self-closing-tags-in-xml-files

Just try this (trailing slash added):

<block class="Magento\Framework\View\Element\Template" name="footer_social" template="Magento_Theme::html/footer_social.phtml"/>
Related Topic