Solved

Use variable in a for cycle

Delio
Shopify Partner
17 0 1

Hello,

I need to have a different menu based on a page variable, I don't know how to insert this variable into the for loop, for example:

 

{% assign menus = aggregate-menu %}
{%- for link in linklists.menus.links -%}

aggregate-menu is the menu handle.

 

How can I insert the menus variable? I have tried many solutions but none are effective

Accepted Solution (1)

nvchien
Shopify Partner
55 21 12

This is an accepted solution.

Hi Delio,

 

Please try to update like this:

{% assign menus = 'aggregate-menu' %}
{%- for link in linklists[menus].links -%}
...

 Also, you can see documentation here: https://shopify.dev/docs/api/liquid/objects/linklist

 

View solution in original post

Replies 2 (2)

nvchien
Shopify Partner
55 21 12

This is an accepted solution.

Hi Delio,

 

Please try to update like this:

{% assign menus = 'aggregate-menu' %}
{%- for link in linklists[menus].links -%}
...

 Also, you can see documentation here: https://shopify.dev/docs/api/liquid/objects/linklist

 

Delio
Shopify Partner
17 0 1

It works, thank you!