0

Currently in Magento 2.3 the dropdown menu only can show the subcategories. I want to change this so that the subcategories are not displayed but only a specific static block.

Inside that block I want to create my own navigation with subcategories and other content.

How can I achieve that?

3
  • If you want to remove the dropdown element completely then use <referenceBlock remove="true" name="navigation.sections" /> in your theme's default.xml file. In the same file you can add a static block via <block class="Magento\Cms\Block\Block"> ... and passing the identifier as an argument. Commented Jan 22, 2019 at 15:49
  • @user7290573 Thanks for the reply! I found the remove element indeed, but I do not know how to add the static block with passing the identifier. Can you show me the entire code for this?
    – JGeer
    Commented Jan 22, 2019 at 17:15
  • Posted the code as an answer - let me know if that works. Commented Jan 22, 2019 at 17:40

2 Answers 2

1

The following code should work when placed inside your theme's default.xml layout file:

<!-- Insert a custom container to the page wrapper -->
<referenceContainer name="page.wrapper">

    <!-- The custom <header> container is called my-header -->
    <container name="my-header" before="-" htmlTag="header" htmlId="my-header">

        <!-- Add a static block with an identifier of header_links_block -->
        <block class="Magento\Cms\Block\Block" name="header_links_block">
            <arguments>
                <argument name="block_id" xsi:type="string">header_links_block</argument>
            </arguments>
        </block>

    </container>

</referenceContainer>

<!-- Remove default navigation section -->
<referenceBlock remove="true" name="navigation.sections" />
4
  • Many thanks! The only problem is that we now can not add a custom block as dropdown to each category. Any idea to how to edit this, so that we can add a custom block to each category as dropdown?
    – JGeer
    Commented Jan 22, 2019 at 21:07
  • @HenkZ I don't fully understand what you mean. Let's say you're viewing a category called "Men's Hoodies & Sweatshirts" - would you want it to automatically show a custom block called mens-hoodies-sweatshirts (for example) and so on for each category? Commented Jan 23, 2019 at 9:31
  • Thanks! What I need is just something like a mega menu module, but I do not want all unnecessary code, because we do not use a lot of the options. The only thing is that we want to create 5 top categories, when hover in the menu it will show a dropdown. And that dropdown should be a unique custom block, so that we can add our own links and images etc.
    – JGeer
    Commented Jan 23, 2019 at 9:45
  • @HenkZ why can't you just add your custom content to the header_links_block block? I still don't understand what you mean exactly - can you link to an example? Commented Jan 23, 2019 at 13:45
0

Was this figured out yet. I'm trying to do the same: Replace the category dropdown with a drop down that, when hovered, will show custom block in a dropdown, like the subcategory does.

1
  • Nope I still have not found a solution to this problem. Do you have found a solution?
    – JGeer
    Commented Dec 22, 2019 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.