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?

Teja Bhagavan Kollepara
3,8275 gold badges33 silver badges69 bronze badges
asked Nov 1, 2017 at 11:48
1
  • let me know if any problem Commented 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

answered Nov 1, 2017 at 12:07
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>? Commented 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 Commented 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 Commented Nov 1, 2017 at 12:24
  • magento.stackexchange.com/a/187029/54588 , displayed ? Commented 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? Commented Nov 1, 2017 at 13:03

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.