2

This a general question about Magento 2 and theme fallback, I currently have a theme which falls back to Snowdog - and then Snowdog falls back to blank.

My question is, when i added:

MyVendor/my_theme/Magento_Theme/layout/default.xml

I seemed to lose all of my links / search / cart from my header, I finally realized that because the blocks did not exist in my theme, it was not going to show anything.

For example I added the following file to my theme:

MyVendor/my_theme/Magento_Search/layout/default.xml

Upon which I regained my search bar and functionality.

But why didn't the fallback work how I thought it was going to?

My understanding of it was that if my theme doesn't have the files, it will automatically fall back to use Snowdog's configuration, and in turn, when Snowdog does not have the files, it will use the Blank theme and when Blank does not have the files, it will lastly attempt to use the Magento core files.

Is my current understanding wrong? Or do I have a problem with my setup?

Edit:

here is my default.xml

<?xml version="1.0"?>
  <!--
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
  <page layout="3columns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="default_head_blocks" />

    <body>
      <block name="require.js" class="Magento\Framework\View\Element\Template" template="Magento_Theme::page/js/require_js.phtml" />
      <referenceContainer name="after.body.start">
        <block class="Magento\RequireJs\Block\Html\Head\Config" name="requirejs-config" />
        <block class="Magento\Translation\Block\Html\Head\Config" name="translate-config" />
        <block class="Magento\Translation\Block\Js" name="translate" template="Magento_Translation::translate.phtml" />
        <block class="Magento\Framework\View\Element\Js\Cookie" name="js_cookies" template="Magento_Theme::js/cookie.phtml" />
        <block class="Magento\Theme\Block\Html\Notices" name="global_notices" template="html/notices.phtml" />
      </referenceContainer>
      <referenceBlock name="top.links">
        <block class="Magento\Theme\Block\Html\Header" name="header" as="header" before="-">
          <arguments>
            <argument name="show_part" xsi:type="string">welcome</argument>
          </arguments>
        </block>
      </referenceBlock>
      <referenceContainer name="main.content">
        <block class="Magento\Framework\View\Element\Template" name="skip_to_content.target" before="-" template="Magento_Theme::html/skiptarget.phtml">
          <arguments>
            <argument name="target_id" xsi:type="string">contentarea</argument>
          </arguments>
        </block>
      </referenceContainer>
      <referenceContainer name="header.container">
        <container name="header.panel.wrapper" htmlClass="panel wrapper" htmlTag="div" before="-">
          <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">header links</argument>
              </arguments>
            </block>
          </container>
        </container>
        <container name="header-wrapper" label="Page Header" as="header-wrapper" htmlTag="div" htmlClass="header content">
          <block class="Magento\Theme\Block\Html\Header\Logo" name="logo">
            <arguments>
              <argument name="logo_img_width" xsi:type="number">189</argument>
              <argument name="logo_img_height" xsi:type="number">64</argument>
            </arguments>
          </block>
        </container>
      </referenceContainer>
      <referenceContainer name="page.top">
        <block class="Magento\Framework\View\Element\Template" name="navigation.sections" before="-" template="Magento_Theme::html/sections.phtml">
          <arguments>
            <argument name="group_name" xsi:type="string">navigation-sections</argument>
            <argument name="group_css" xsi:type="string">nav-sections</argument>
          </arguments>
          <block class="Magento\Framework\View\Element\Template" name="store.menu" group="navigation-sections" template="Magento_Theme::html/container.phtml">
            <arguments>
              <argument name="title" translate="true" xsi:type="string">Menu</argument>
            </arguments>
            <block class="Magento\Theme\Block\Html\Topmenu" name="catalog.topnav" template="html/topmenu.phtml" ttl="3600" before="-" />
          </block>
          <block class="Magento\Framework\View\Element\Text" name="store.links" group="navigation-sections">
            <arguments>
              <argument name="title" translate="true" xsi:type="string">Account</argument>
              <argument name="use_force" xsi:type="boolean">true</argument>
              <argument name="text" xsi:type="string">
                <![CDATA[<!-- Account links -->]]>
              </argument>
            </arguments>
          </block>
          <block class="Magento\Framework\View\Element\Template" name="store.settings" group="navigation-sections" template="Magento_Theme::html/container.phtml">
            <arguments>
              <argument name="title" translate="true" xsi:type="string">Settings</argument>
            </arguments>
            <block class="Magento\Store\Block\Switcher" name="store.settings.language" template="switch/languages.phtml">
              <arguments>
                <argument name="id_modifier" xsi:type="string">nav</argument>
              </arguments>
            </block>
            <block class="Magento\Directory\Block\Currency" name="store.settings.currency" template="currency.phtml">
              <arguments>
                <argument name="id_modifier" xsi:type="string">nav</argument>
              </arguments>
            </block>
          </block>
        </block>
        <container name="top.container" as="topContainer" label="After Page Header Top" htmlTag="div" htmlClass="top-container" />
        <block class="Magento\Theme\Block\Html\Breadcrumbs" name="breadcrumbs" as="breadcrumbs" />
      </referenceContainer>
      <referenceContainer name="columns.top">
        <block class="Magento\Theme\Block\Html\Title" name="page.main.title" template="html/title.phtml" />
        <container name="page.messages" htmlTag="div" htmlClass="page messages">
          <block class="Magento\Framework\View\Element\Template" name="ajax.message.placeholder" template="Magento_Theme::html/messages.phtml" />
          <block class="Magento\Framework\View\Element\Messages" name="messages" as="messages" template="Magento_Theme::messages.phtml" />
        </container>
      </referenceContainer>
      <referenceContainer name="main">
        <container name="content.top" label="Main Content Top" />
        <container name="content" label="Main Content Area" />
        <container name="content.aside" label="Main Content Aside" />
        <container name="content.bottom" label="Main Content Bottom" />
      </referenceContainer>
      <referenceContainer name="page.bottom.container">
        <container name="page.bottom" label="Before Page Footer" htmlTag="div" htmlClass="content" />
      </referenceContainer>
      <referenceContainer name="footer-container">
        <container name="footer" as="footer" label="Page Footer" htmlTag="div" htmlClass="footer content">
          <block class="Magento\Store\Block\Switcher" name="store_switcher" as="store_switcher" template="switch/stores.phtml" />
          <block class="Magento\Framework\View\Element\Html\Links" name="footer_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" />
          <block class="Magento\Framework\View\Element\Template" name="report.bugs" template="Magento_Theme::html/bugreport.phtml" />
        </container>
      </referenceContainer>
      <referenceContainer name="before.body.end">
        <block class="Magento\Theme\Block\Html\Footer" name="absolute_footer" template="html/absolute_footer.phtml" />
      </referenceContainer>
      <referenceContainer name="content">
        <block class="Magento\Framework\View\Element\FormKey" name="formkey" />
      </referenceContainer>
    </body>
  </page>
  • yes, your understanding is correct. – Rakesh Jesadiya Aug 30 '16 at 12:08
  • what is the issue at you stuck? – Rakesh Jesadiya Aug 30 '16 at 12:23
  • My issue was when i added: MyVendor/my_theme/Magento_Theme/layout/default.xml I would lose all of my header blocks. So search / links / cart would disappear, however when i commented out the default.xml it would come back. It wasn't cache. – andy jones Aug 30 '16 at 12:25
  • plz show your full code of default.xml – Rakesh Jesadiya Aug 30 '16 at 12:32
  • It is the default from vender/magento/module-theme/view/frontend/layout I have added it to the question. – andy jones Aug 30 '16 at 12:42
2

Whenever you have to override core layout file you have to keep only your required code inside xml not keep full xml code of your core file.

Keep inside your theme file, for default.xml

magento2/app/design/frontend/Vendor/themename/Magento_Theme/layout/default.xml

Now inside xml file,

<?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>
   <!-- keep your code here -->
</body>
</page>

Clean cache and your changes are display inside your site.

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.