I want different Menus on different Pages in my Shopify Store but my code doesn’t work. If i use my code it shows me no menu also the mainmenu is not visible.
I created a Page and a Page Template
I code this at the top of the file header-drawer.liquid after comment
Your code has a couple of syntax errors and logical issues. Here’s how you can properly implement different menus for different pages in your Shopify store:
Fixes & Corrections:
Remove extra == in the if statement
Correct the assignment of the new menu
Use the correct way to reference the link list
Corrected Code for header-drawer.liquid
{% if page.handle == "PageTemplateName" %}
{% assign _new_menu = linklists.HandleMenuName.links %}
{% else %}
{% assign _new_menu = section.settings.menu.links %}
{% endif %}
{%- for link in _new_menu -%}
- {{ link.title }}
{%- endfor -%}
Key Fixes:
Removed contains ==, which was incorrect. Instead, use == for exact matches or contains for partial matches.
Removed section._new_menu, since _new_menu is a variable, not part of the section object.
For header-dropdown-menu.liquid & header-mega-menu.liquid
Repeat the same logic in those files where you loop through the menu.