跳至內容
選單
此問題已被標幟
1 回覆
10419 瀏覽次數

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


頭像
捨棄
最佳答案

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

頭像
捨棄

<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>

作者

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

相關帖文 回覆 瀏覽次數 活動
1
4月 24
4011
1
2月 23
4062
0
10月 21
3055
3
10月 20
5487
7
3月 24
9904