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?

  • 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. – user7290573 Jan 22 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? – Henk Z Jan 22 at 17:15
  • Posted the code as an answer - let me know if that works. – user7290573 Jan 22 at 17:40
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" />
  • 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? – Henk Z Jan 22 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? – user7290573 Jan 23 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. – Henk Z Jan 23 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? – user7290573 Jan 23 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.

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.