Variable inside the liquid, if the application when calling store settings

I thought this would be easy to solve, but I'm trying to put a variable in a liquid expression.

I have my variable {{ loop_index }} and I want it to be in this expression:

 {% if settings.dropdown-[loop_index]-select %} 

I tried to put [...] around him, but that didn't work. Basically this should indicate settings.dropdown-1-select, settings.dropdown-2-select.

What am I doing wrong?

+4
source share
1 answer

Create a string containing the variable name, then use the notation square bracket to access the settings with that name. For instance:

 {% capture var %}dropdown-{{ loop_index }}-select{% endcapture %} {% if settings[var] %} 
+7
source

Source: https://habr.com/ru/post/986897/


All Articles