Variable within liquid if statement when calling shopify settings

大城市里の小女人 提交于 2019-11-30 17:31:05

问题


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?


回答1:


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

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


来源:https://stackoverflow.com/questions/28770065/variable-within-liquid-if-statement-when-calling-shopify-settings

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!