add different menus for different pages

add different menus for different pages

findfy
Shopify Partner
3 0 2

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

{% if page.handle contains == "PageTemplateName" %}
{% assign _new_menu = linklists.HandleMenuName.links %}  
  {% else %}
{% assign _new_menu = section.settings.menu.links %}  
{% endif %}>

And i replace on line 10 {%- for link in section.settings.menu.links -%} with {%- for link in section._new_menu -%}

After that i repeat the steps with header-dropdown-menu.liquid and header-mega-menu.liquid

 
Replies 2 (2)

suyash1
Shopify Partner
10716 1324 1700

@findfy page handle gets page name in the url, is your page name "PageTemplateName" , please check in url

 

Support me | To build shopify pages use PAGEFLY | Contact me - suyash.patankar@gmail.com , My timezone is GMT+5:30.

devcoders
Shopify Partner
1154 138 330

Hello @findfy 

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 -%}
<li>
<a href="{{ link.url }}">{{ link.title }}</a>
</li>
{%- 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.

Let me know if you need further refinements!

Shopify Developer: Helping eCommerce Stores
If you need assistance with your store, feel free to contact us at devcodersp@gmail.com
WhatsApp No: +91 8516919310 If my assistance was helpful, please consider liking and accepting the solution. Thank you!