Skip to Content
Menu
This question has been flagged
1 Atsakyti
9386 Rodiniai

When adding a Sub menu on a main menu item, the link for the Top page changes to # and is lost unless adding the link to the Top page within the sub menu again. This is not elegant. 

For example:


Top Menu 

  • Home /home
  • Products /products

Menu with Sub menu

  • Home /home
  • Products /# - changes to a dead anchor
    • ItemOne /item-one
    • ItemTwo /item-two 

Setting Website > Edit > Navbar > Sub menu option "On Hover" doesn't have any effect.

Is there a quick method to keep this link to the /product page active with a sub menu?


Thanks


Portretas
Atmesti
Best Answer

Hello,

You need Inherit the base website sub menu template and change the code.
Code is in the Comment section.
Hope this solution is helpful for you.

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Portretas
Atmesti

<template id="custom_submenu" inherit_id="website.submenu">
<xpath expr="//li[2]/a[1]" position="replace">
<a t-attf-class="#{link_class or ''} dropdown-toggle #{submenu.is_mega_menu and 'o_mega_menu_toggle'}" data-toggle="dropdown" t-att-href="submenu.clean_url()">
<span t-field="submenu.name"/>
</a>
</xpath>
</template>

Autorius

Thanks for the quick answer and solution.

Technically, it worked as described. The correct link now appears on the Top Menu item.

However, when it's clicked - it does not direct to the page. Logically this is correct when the "On Click" option is enabled.
When "On Hover" option is enabled, It would be good to allow the link to be clicked to go to the page.

any thoughts if this could be tweaked?

Many Thanks!

Hello,

You need to handle "click" events on the website menus.
You need to handle down "arrow" and menu "label", On click of the arrow the sub menus will be displayed and On click of menu label the URL Link should be redirected.

Hello,
After inheriting the base website sub-menu template and changing the code as Jainesh mentioned, you need to go to the theme tab in the website editor, scroll down to Website settings section, click on "</body>" button beside the code injection field, and there add the following code:

<script>
var productLinks = document.querySelectorAll('a[href="/product"]');
if (productLinks .length > 0) {
productLinks .forEach(function(link) {
link.addEventListener("click", function(event) {
event.preventDefault(); // Prevent the default link behavior
window.location.href = link.getAttribute("href");
});
});
}
</script>

Thank you for giving the idea

Related Posts Replies Rodiniai Veikla
1
bal. 24
1674
1
vas. 23
1991
0
spal. 21
2623
3
spal. 20
4713
7
kov. 24
9169