Layout file that moves a block breaks entire layout
-
09-10-2020 - |
سؤال
I'm running Magento 2.1.7 CE and I need to move the navigation.sections
block inside of the header-wrapper
. I found the reference to navigation.sections
in vendor/magento/module-theme/view/frontend/layout/default.xml
so I created a theme and I'm trying to modify the layout to just move that one block.
Here's the XML I setup to move navigation.sections
inside of header-wrapper
(saved under app/design/frontend/ThemeName/default/Magento_Theme/layout/default.xml
):
<?xml version="1.0"?>
<page layout="3columns"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<move element="navigation.sections" destination="header-wrapper" before="logo" />
</body>
</page>
This technically works and when I apply this theme the navigation.sections
block is moved to that container, but only in developer mode. If I change to production mode with this theme enabled, I run into these issues:
magento setup:static-content:deploy
fails (I need to clear a lot of directories undervar/
to get it to work)- Cannot minify or bundle JS or CSS, it just fails
- Layout on the front page is completely wrecked
- Some CSS and JavaScript files 404. From what I've seen it's files like
require.js
that are included in the originallayout.xml
that I'm trying to extend
I tried copying the original layout.xml
and just adding the move
tag but no luck. The only way I can get it to work without Magento having a meltdown is by adding the move
tag to the original file, but that's not what I want.
What am I doing wrong?
Here is my registration.php
:
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::THEME,
'frontend/ThemeName/default',
__DIR__
);
Here's my theme.xml
:
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
<!-- Theme's name -->
<title>Theme Name</title>
<!-- Parent theme -->
<parent>Magento/luma</parent>
<media>
<!-- Theme's preview image -->
<preview_image>media/preview.jpg</preview_image>
</media>
</theme>
I found this in var/logs/exception.log
:
"/path/to/magento/pub/static/frontend/ThemeName/default/en_US/mage/requirejs/mixins.js"
Warning!file_get_contents(/path/to/magento/pub/static/frontend/ThemeName/default/en_US/mage/requirejs/mixins.js):
failed to open stream: No such file or directory in /path/to/magento/vendor/magento/framework/Filesystem/Driver/File.php:149
So the compilation step is looking for requirejs/mixins.js
which is NOT in my theme, I just want those pulled from the Luma theme. Again, what's an actual fix for this?
This is how I have been clearing cache so far:
rm -rf var/cache/* var/generation/* var/view_preprocessed/* var/page_cache/* pub/static/* var/di/* \
&& php bin/magento cache:flush
المحلول
This is a Magento bug: https://github.com/magento/magento2/issues/3754
Currently the workaround is to add a file under theme/web/images
, e.g.: theme/web/images/dummy.jpg