4

I am working on a Magento 2.1.7 shop and I have created a child-theme of Magento Blank.

In the back-end, I have created a block with a custom, hard-coded, navigation like:

<nav>
 <ul>
  <li><a href="http://www.examplewebsite.com/">Home</a></li>
  <li><a href="http://www.examplewebsite.com/about">About</a></li>
  <li><a href="http://www.examplewebsite.com/blog">Blog</a></li>
  <li><a href="http://www.examplewebsite.com/contact">Contact Us</a></li>
 </ul>
</nav>

By default, Magento displays links to the product categories in the top menu:

<block class="Magento\Theme\Block\Html\Topmenu" name="catalog.topnav" template="html/topmenu.phtml" ttl="3600" before="-"/>

How do I, instead, display my custom links block?

1
  • let me know if any problem Nov 1, 2017 at 12:13

1 Answer 1

5

To show your Custom Block Navigation , you simply need to create a widget

  • Go to admin > content > widgets > add widget

  • Select type as CMS static Block and choose your theme whichever you are using

  • Fill all the details ( Title / Assign to Store Views / Sort Order to "0"

  • Add layout update > Display on all pages / Container: After page header

  • Widget options > Select your block

Keep your cache disabled or clean/flush your cache

You can remove your default navigation by below code in your custom Magento_Theme module, if required.

<referenceBlock name="catalog.topnav" remove="true" />

Magento_Theme\layout\default.xml

I hope this will help you out and others as well

13
  • I did all the above and the default navigation is displayed as well. Can I alternatively make changes in defaul.xml considering that <block class="Magento\Framework\View\Element\Template" name="store.menu" group="navigation-sections" template="Magento_Theme::html/container.phtml"> <block class="Magento\Theme\Block\Html\Topmenu" name="catalog.topnav" template="html/topmenu.phtml" ttl="3600" before="-" remove="true"/> </block>? Nov 1, 2017 at 12:17
  • No need to do any coding in XML just simple create widget , see working example here smartparcelbox.com .. navigation and each block on homepage displayed via widget and blocks Nov 1, 2017 at 12:18
  • first , display your static block on front end using widget ... then we will remove default menu.... flush your cache or check in different browser , if you created widget in above mentioned way then it should display Nov 1, 2017 at 12:24
  • magento.stackexchange.com/a/187029/54588 , displayed ? Nov 1, 2017 at 12:31
  • I can not use <referenceBlock name="catalog.topnav" remove="true" /> because I need to display the categories on the page still, but in the sidebar. What alternative do I have? Nov 1, 2017 at 13:03

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.