Magento 2.2.2 - Move custom navigation into header-wrapper in XML and make it responsive
Below xml adds custom navigation before category. To make it responsive I have included it under block navigation.sections
.
<referenceBlock name="navigation.sections">
<arguments>
<argument name="group_name" xsi:type="string">navigation-sections</argument>
<argument name="group_css" xsi:type="string">nav-sections</argument>
</arguments>
<block class="MagentoFrameworkViewElementTemplate" name="sub.nav" group="navigation-sections" template="Magento_Theme::html/header_links.phtml">
<arguments>
<argument name="title" translate="true" xsi:type="string">Sub Nav</argument>
</arguments>
</block>
</referenceBlock>
But now it break my HTML structure as I want this custom block to be inside header.wrapper and at the same time responsive. I tried below but its not working
<move element="sub.nav" destination="header-wrapper" after="logo"/>
Although navigation.sections
can be moved into header and its responsive too.
<move element="navigation.sections" destination="header-wrapper" after="logo"/>
If I change referenceBlock
to header.wrapper, the navigation goes inside header but then it is not working for responsive mode. How do I move my custom navigation inside header.wrapper
and make it responsive also ?
magento2 xml navigation
bumped to the homepage by Community♦ 15 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
Below xml adds custom navigation before category. To make it responsive I have included it under block navigation.sections
.
<referenceBlock name="navigation.sections">
<arguments>
<argument name="group_name" xsi:type="string">navigation-sections</argument>
<argument name="group_css" xsi:type="string">nav-sections</argument>
</arguments>
<block class="MagentoFrameworkViewElementTemplate" name="sub.nav" group="navigation-sections" template="Magento_Theme::html/header_links.phtml">
<arguments>
<argument name="title" translate="true" xsi:type="string">Sub Nav</argument>
</arguments>
</block>
</referenceBlock>
But now it break my HTML structure as I want this custom block to be inside header.wrapper and at the same time responsive. I tried below but its not working
<move element="sub.nav" destination="header-wrapper" after="logo"/>
Although navigation.sections
can be moved into header and its responsive too.
<move element="navigation.sections" destination="header-wrapper" after="logo"/>
If I change referenceBlock
to header.wrapper, the navigation goes inside header but then it is not working for responsive mode. How do I move my custom navigation inside header.wrapper
and make it responsive also ?
magento2 xml navigation
bumped to the homepage by Community♦ 15 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
I am having the same problem
– Stephen Dance
Feb 9 '18 at 14:13
add a comment |
Below xml adds custom navigation before category. To make it responsive I have included it under block navigation.sections
.
<referenceBlock name="navigation.sections">
<arguments>
<argument name="group_name" xsi:type="string">navigation-sections</argument>
<argument name="group_css" xsi:type="string">nav-sections</argument>
</arguments>
<block class="MagentoFrameworkViewElementTemplate" name="sub.nav" group="navigation-sections" template="Magento_Theme::html/header_links.phtml">
<arguments>
<argument name="title" translate="true" xsi:type="string">Sub Nav</argument>
</arguments>
</block>
</referenceBlock>
But now it break my HTML structure as I want this custom block to be inside header.wrapper and at the same time responsive. I tried below but its not working
<move element="sub.nav" destination="header-wrapper" after="logo"/>
Although navigation.sections
can be moved into header and its responsive too.
<move element="navigation.sections" destination="header-wrapper" after="logo"/>
If I change referenceBlock
to header.wrapper, the navigation goes inside header but then it is not working for responsive mode. How do I move my custom navigation inside header.wrapper
and make it responsive also ?
magento2 xml navigation
Below xml adds custom navigation before category. To make it responsive I have included it under block navigation.sections
.
<referenceBlock name="navigation.sections">
<arguments>
<argument name="group_name" xsi:type="string">navigation-sections</argument>
<argument name="group_css" xsi:type="string">nav-sections</argument>
</arguments>
<block class="MagentoFrameworkViewElementTemplate" name="sub.nav" group="navigation-sections" template="Magento_Theme::html/header_links.phtml">
<arguments>
<argument name="title" translate="true" xsi:type="string">Sub Nav</argument>
</arguments>
</block>
</referenceBlock>
But now it break my HTML structure as I want this custom block to be inside header.wrapper and at the same time responsive. I tried below but its not working
<move element="sub.nav" destination="header-wrapper" after="logo"/>
Although navigation.sections
can be moved into header and its responsive too.
<move element="navigation.sections" destination="header-wrapper" after="logo"/>
If I change referenceBlock
to header.wrapper, the navigation goes inside header but then it is not working for responsive mode. How do I move my custom navigation inside header.wrapper
and make it responsive also ?
magento2 xml navigation
magento2 xml navigation
asked Jan 12 '18 at 10:06
SlimshadddyyySlimshadddyyy
61011547
61011547
bumped to the homepage by Community♦ 15 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 15 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
I am having the same problem
– Stephen Dance
Feb 9 '18 at 14:13
add a comment |
I am having the same problem
– Stephen Dance
Feb 9 '18 at 14:13
I am having the same problem
– Stephen Dance
Feb 9 '18 at 14:13
I am having the same problem
– Stephen Dance
Feb 9 '18 at 14:13
add a comment |
1 Answer
1
active
oldest
votes
What I did as a workaround is to duplicate the topmenu layout, leaving the original for mobile and the new one for desktop. Then with CSS you can show/hide the desired menu. Something like this:
default.xml
<referenceContainer name="header-wrapper">
<container name="topmenu.desktop"
as="topmenu.desktop"
label="Top Menu - Desktop"
htmlTag="div"
htmlClass="topmenu-desktop"
after="logo">
<block class="MagentoThemeBlockHtmlTopmenu"
name="catalog.topnav.desktop"
template="Magento_Theme::html/topmenu.phtml"
ttl="3600"/>
</container>
</referenceContainer>
CSS
/* Hide the original Navigation menu on Desktop */
.nav-sections {
@media (min-width: @min_tablet) { display: none; }
}
/* Hide the duplicated Navigation menu on Mobile */
.page-header {
.header.content {
.topmenu-desktop {
@media (max-width: @max_tablet) { display: none; }
}
}
}
Note: I added the custom links to the Top Menu as explained here, so the links inherit the navigation classes
Hope it helps.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f209229%2fmagento-2-2-2-move-custom-navigation-into-header-wrapper-in-xml-and-make-it-re%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
What I did as a workaround is to duplicate the topmenu layout, leaving the original for mobile and the new one for desktop. Then with CSS you can show/hide the desired menu. Something like this:
default.xml
<referenceContainer name="header-wrapper">
<container name="topmenu.desktop"
as="topmenu.desktop"
label="Top Menu - Desktop"
htmlTag="div"
htmlClass="topmenu-desktop"
after="logo">
<block class="MagentoThemeBlockHtmlTopmenu"
name="catalog.topnav.desktop"
template="Magento_Theme::html/topmenu.phtml"
ttl="3600"/>
</container>
</referenceContainer>
CSS
/* Hide the original Navigation menu on Desktop */
.nav-sections {
@media (min-width: @min_tablet) { display: none; }
}
/* Hide the duplicated Navigation menu on Mobile */
.page-header {
.header.content {
.topmenu-desktop {
@media (max-width: @max_tablet) { display: none; }
}
}
}
Note: I added the custom links to the Top Menu as explained here, so the links inherit the navigation classes
Hope it helps.
add a comment |
What I did as a workaround is to duplicate the topmenu layout, leaving the original for mobile and the new one for desktop. Then with CSS you can show/hide the desired menu. Something like this:
default.xml
<referenceContainer name="header-wrapper">
<container name="topmenu.desktop"
as="topmenu.desktop"
label="Top Menu - Desktop"
htmlTag="div"
htmlClass="topmenu-desktop"
after="logo">
<block class="MagentoThemeBlockHtmlTopmenu"
name="catalog.topnav.desktop"
template="Magento_Theme::html/topmenu.phtml"
ttl="3600"/>
</container>
</referenceContainer>
CSS
/* Hide the original Navigation menu on Desktop */
.nav-sections {
@media (min-width: @min_tablet) { display: none; }
}
/* Hide the duplicated Navigation menu on Mobile */
.page-header {
.header.content {
.topmenu-desktop {
@media (max-width: @max_tablet) { display: none; }
}
}
}
Note: I added the custom links to the Top Menu as explained here, so the links inherit the navigation classes
Hope it helps.
add a comment |
What I did as a workaround is to duplicate the topmenu layout, leaving the original for mobile and the new one for desktop. Then with CSS you can show/hide the desired menu. Something like this:
default.xml
<referenceContainer name="header-wrapper">
<container name="topmenu.desktop"
as="topmenu.desktop"
label="Top Menu - Desktop"
htmlTag="div"
htmlClass="topmenu-desktop"
after="logo">
<block class="MagentoThemeBlockHtmlTopmenu"
name="catalog.topnav.desktop"
template="Magento_Theme::html/topmenu.phtml"
ttl="3600"/>
</container>
</referenceContainer>
CSS
/* Hide the original Navigation menu on Desktop */
.nav-sections {
@media (min-width: @min_tablet) { display: none; }
}
/* Hide the duplicated Navigation menu on Mobile */
.page-header {
.header.content {
.topmenu-desktop {
@media (max-width: @max_tablet) { display: none; }
}
}
}
Note: I added the custom links to the Top Menu as explained here, so the links inherit the navigation classes
Hope it helps.
What I did as a workaround is to duplicate the topmenu layout, leaving the original for mobile and the new one for desktop. Then with CSS you can show/hide the desired menu. Something like this:
default.xml
<referenceContainer name="header-wrapper">
<container name="topmenu.desktop"
as="topmenu.desktop"
label="Top Menu - Desktop"
htmlTag="div"
htmlClass="topmenu-desktop"
after="logo">
<block class="MagentoThemeBlockHtmlTopmenu"
name="catalog.topnav.desktop"
template="Magento_Theme::html/topmenu.phtml"
ttl="3600"/>
</container>
</referenceContainer>
CSS
/* Hide the original Navigation menu on Desktop */
.nav-sections {
@media (min-width: @min_tablet) { display: none; }
}
/* Hide the duplicated Navigation menu on Mobile */
.page-header {
.header.content {
.topmenu-desktop {
@media (max-width: @max_tablet) { display: none; }
}
}
}
Note: I added the custom links to the Top Menu as explained here, so the links inherit the navigation classes
Hope it helps.
answered Feb 23 '18 at 0:13
piniciopinicio
573412
573412
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f209229%2fmagento-2-2-2-move-custom-navigation-into-header-wrapper-in-xml-and-make-it-re%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I am having the same problem
– Stephen Dance
Feb 9 '18 at 14:13