Variable within liquid if statement when calling shopify settings
I thought this would be simple to solve but I am trying to put a variable within a liquid statement.
I have my variable{{ loop_index }}
and I want it to be within this statement :
{% if settings.dropdown-[loop_index]-select %}
I tried putting [...] round it but that didn't work. Basically it should say settings.dropdown-1-select, settings.dropdown-2-select.
What am I doing wrong?
Answer
Solution:
Create a string containing the variable name, then use the square bracket notation (http://docs.shopify.com/themes/liquid-documentation/basics/handle#attributes-handle) to access the setting with that name. For example:
{% capture var %}dropdown-{{ loop_index }}-select{% endcapture %}
{% if settings[var] %}
Source
Didn't find the answer?
Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.