add different menus for different pages

Topic summary

A user is attempting to display different navigation menus on different pages in their Shopify store but encountering issues where no menus appear, including the main menu.

Implementation approach:

  • Created a custom page template
  • Modified header-drawer.liquid, header-dropdown-menu.liquid, and header-mega-menu.liquid files
  • Added conditional logic to check page handle and assign appropriate menu

Identified problems:

  • Syntax error: contains == is invalid (should be either == for exact match or contains for partial match)
  • Variable reference error: Used section._new_menu instead of just _new_menu
  • Typo in variable name assignment

Solution provided:
Corrected code using {% if page.handle == "PageTemplateName" %} with proper variable assignment and loop structure. One responder also suggested verifying the actual page handle matches the URL slug being checked.

Status: Solution offered with corrected Liquid syntax; awaiting confirmation if fixes resolve the issue.

Summarized with AI on October 31. AI used: claude-sonnet-4-5-20250929.

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

1 Like

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

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 -%}
- {{ 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.

Let me know if you need further refinements!