{% for item in linklists.primary-nav.links %}
<span>{{ item.handle }}</span>
{% for subItem in item.links %}
<span>{{ subItem.handle }}</span>
{% endfor %}
{% endfor %}
But I want to access only the submenu items under category_2 directly. I tried these approaches but they don’t work:
{% for item in linklists.primary-nav.category_2.links %}
<span>{{ item.handle }}</span>
{% endfor %}
And this one too:
{% for item in linklists.category_2.links %}
<span>{{ item.handle }}</span>
{% endfor %}
Can I directly reference a specific menu section to get its child links? Or do I have to loop through the main menu first to find the right parent item?
yeah, u gotta loop through the main menu to find the parent first. shopify doesn’t let ya access submenus directly. try this {% assign cat2 = linklists.primary-nav.links | where: 'handle', 'category-2' | first %} then loop through cat2.links if it exists. kinda annoying but that’s how liquid works.
Filters work but they’re a pain with multiple menu operations.
I hit this same problem building a custom nav system. Instead of fighting Liquid’s limitations, I automated it - pulls menu data through Shopify’s API and restructures it exactly how you need it.
The workflow grabs your nav structure, creates direct references to submenus, and can auto-update theme files. No more parent loops or complex filters.
Set it to run when you update menus and your nav code stays clean with direct submenu access. Way better than wrestling with Liquid manually.
unfortunately there’s no shortcut - shopify’s liquid engine makes ya traverse the parent structure first. i usually create a custom filter or use {% tablerow %} with conditions to clean it up, but ya still gotta loop through primary-nav first then target your specific parent handle.
Nope, Shopify’s Liquid doesn’t let you access submenus directly like that. You’ll have to use the loop, but here’s a cleaner way with conditional logic: {% for item in linklists.primary-nav.links %}{% if item.handle == 'category-2' %}{% for subitem in item.links %}{{ subitem.handle }}{% endfor %}{% endif %}{% endfor %}. I’ve been doing Shopify themes for three years and this always catches new developers off guard. The assign filter works too but it’s slower on big menus since it processes everything first.
Shopify treats navigation as a hierarchical object structure instead of flat endpoints you can access directly. I hit this same problem building a mega menu component last year and ended up with a custom solution using capture tags to grab the specific submenu once I found it. Something like {% capture category_2_items %}{% for item in linklists.primary-nav.links %}{% if item.handle contains 'category-2' %}{% for sub in item.links %}{{ sub.url }}|{{ sub.title }}{% unless forloop.last %}||{% endunless %}{% endfor %}{% endif %}{% endfor %}{% endcapture %} then split the captured string when you need it. It’s not pretty but performs way better than repeated filtering, especially if you’re referencing those submenus multiple times across different template sections.