magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.54k stars 9.32k forks source link

How to extend default.xml file in Magento_Theme #2996

Closed cs221313 closed 8 years ago

cs221313 commented 8 years ago

Hi, all,

I want to add a static block at the top of page. It works when I put the code in app/design/frontend/Magento/blank/Magento_Theme/layout/default.xml. The content is as following:

<?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="header.container">
            **<block class="Magento\Cms\Block\Block" name="home_top" before="header.panel.wrapper">
                <arguments>
                    <argument name="block_id" xsi:type="string">home_top</argument>
                </arguments>
            </block>**
            <container name="header.panel.wrapper" htmlClass="panel wrapper" htmlTag="div" before="-"/>
        </referenceContainer>
        <move element="header.panel" destination="header.panel.wrapper"/>
        <move element="top.links" destination="header.panel" after="-"/>
        <move element="catalog.topnav" destination="store.menu" before="-"/>
        <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>
                <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" before="store_language" template="currency.phtml">
                        <arguments>
                            <argument name="id_modifier" xsi:type="string">nav</argument>
                        </arguments>
                    </block>
                </block>
            </block>
        </referenceContainer>
    </body>
</page>

home_top static block is what I added. It works But when I put that code in my theme: /app/design/frontend/MyNamespace/MyTheme/Magento_Theme/layout/default.xml as following:

<?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="header.container">
            <block class="Magento\Cms\Block\Block" name="home_top" before="header.panel.wrapper">
                <arguments>
                    <argument name="block_id" xsi:type="string">home_top</argument>
                </arguments>
            </block>
            <container name="header.panel.wrapper" htmlClass="panel wrapper" htmlTag="div" before="-"/>
        </referenceContainer>
    </body>
</page>

It doesn't work. Can anyone can help me?

Thanks a lot

David

almarchenko commented 8 years ago

Hi David! Does your theme inherit from the Blank theme? Did you apply your theme in the Admin? (in the configuration under CONTENT > Design > Themes)

cs221313 commented 8 years ago

Yes. My theme inherited from the Blank theme. When I changed the default.xml in Blank theme it works. But I put the code in my theme, it does not work.

alankent commented 8 years ago

What is the exact path name to the default.xml file you put in your theme? A common error is the path name is wrong and the file is not picked up as a result.

Here is a play theme I was trying (and works):

app/design/frontend/AlanKent/footerimage/Magento_Theme/layout/default.xml

<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="Magento\Framework\View\Element\Template"
             name="footer.image"
             before="-"
             template="Magento_Theme::html/footerimage.phtml" />
    </referenceContainer>
  </body>
</page>

Something I do sometimes is to put a syntax error in and check the var/log directory. If there is no error, then its not finding you file.

cs221313 commented 8 years ago

My default.xml file is at: /app/design/frontend/MyNamespace/MyTheme/Magento_Theme/layout/default.xml

I modified the default.xml file to put a syntax error. but no error reported in log files. I don't know why my default.xml could not be found.

cs221313 commented 8 years ago

image my _extend.less and _theme.less files could be found. But the default.xml could not be found. so weird.

alankent commented 8 years ago

Ok, so its clearly registered, you have selected it in Admin UI, but var/log/* is not reporting a syntax error when you put one into the file. Strange. I assume you have flushed all the caches again for good luck (including the three buttons under the big table)?

IceReaper commented 8 years ago

It worked after changing line endings to unix and encoding to utf8 in sublime - major problem here...

almarchenko commented 8 years ago

@IceReaper Thanks for sharing! Did you originally copy the code sample from our docs or no?

IceReaper commented 8 years ago

Copied several things together (also some stuff from the docs). Goal was to do exactly this: http://magento.stackexchange.com/questions/93628/magento-2-remove-and-change-footer-links Xml file kept not loading, tried so many things, wasted a whole day for this. So i used a sublime plugin to convert the file to utf8, unix line endings and then it suddenly worked.

almarchenko commented 8 years ago

Thanks!

cs221313 commented 8 years ago

After I debug the Theme.php file. I found my theme type is virtual. But the theme type should be physical.If the theme is virtual, this theme could not extend the parent theme. Does anyone know how to set the theme to physical?

Thanks a lot

cs221313 commented 8 years ago

After debugged the code. I got the reason why I can not extend my theme. It's because my type is 1 which is virtual type. I changed it to 0 which is physical type. It works now. image

But the question is this type value is assigned automatically when I created that theme. I can not change it at the backend. Is there any other way to modify that value. because I don't think it's a good way to change the value at the DB directly.

Thanks

almarchenko commented 8 years ago

@cs221313 Great that you found the solution. But this is unusual. We cannot reproduce it. Could you post your theme files? (theme.xml, registration.php. composer.json) Thank you.

cs221313 commented 8 years ago

theme.xml

image

registration.php

<?php /**

composer.json

{ "name": "aimai/theme-frontend-whoo", "description": "N/A", "require": { "php": "~5.5.0|~5.6.0|~7.0.0", "magento/theme-frontend-blank": "100.0.", "magento/framework": "100.0." }, "type": "magento2-theme", "version": "100.0.2", "license": [ "OSL-3.0", "AFL-3.0" ], "autoload": { "files": [ "registration.php" ] } }

mswaidan commented 8 years ago

@cs221313 thanks, I was having the same problem, and my theme was also type = 1. changing to 0 allowed my default.xml to work.

serzhik commented 8 years ago

Got same issue. Thanks for fix.

Can't reproduce one more time.

moleculech commented 8 years ago

Same here, happend after migrating database to a separate installation. Thanks for the help!

sitepodmatt commented 8 years ago

Is there a related issue open for this? Surely we're not going to close this silent failing with no debug hints as ok

mswaidan commented 7 years ago

This happened again to me, seems that it's after I do an update.

ayaccop commented 7 years ago

Face the same problem as well on 2.1.2, after update at db from virtual to physical, it works just fine.

tsouthwi1524 commented 6 years ago

This happened to me as well when installing an extension. I made the change in the database. Is there a better way to handle this?

ngocvon commented 6 years ago

I like you. Can you help fix error no load file default.xml

johnmpasq commented 6 years ago

Happened to me as well when installing an extension. It changed the physical theme to virtual theme.

dni commented 5 years ago

yes is happening to me aswell using magento 2.3.0

luizventurote commented 5 years ago

I had the same issue with Magento 2.3.0.

flytomek commented 4 years ago

Same issue in Magento 2.3.3 + Docker env. Changing type of theme to 0 helped.

JamesTheHacker commented 4 years ago

Could somebody tell me why the theme gets set to virtual? I've just had this problem with 2.4 and it took me a while to solve. Changing the theme's type to 0 worked.

cd-tungho commented 1 year ago

I was having the same issue. In my case, like @mswaidan, I changed the theme type = 0. And it works after that. Do you guys have any documents about this theme type? Thanks.

alexwatever commented 1 year ago

This issue popped up for us while using Magento 2.4.5, for a theme used in multiple environments, though this only affected one.