interpolation - Shopify Liquid How do I use for-loop index variables in an assign or capture tag? -
i getting liquid template coding on shopify site. how use for-loop index/variable when defining variable names in assign or capture tags? ie: i'm trying condense code create multiple link menus sequentially numbered settings, [i] number between 2 , 4 in settings key.
what proper syntax insert number a) tag if statement or assign. b) interpolated text in h3 element below. c) nested/bracketed key statement (sorry if that's not called, i'm still learning), in second statement.
{% in (2..4) %} {% if settings.footer_quicklinks_enable[i] %} <div class="grid-item medium--one-half large--three-twelfths"> <h3>{{ 'layout.footer.quick_links{{i}}' | t }}</h3> <ul> {% link in linklists[settings.footer_quicklinks_linklist[i]].links %} <li><a href="{{ link.url }}">{{ link.title }}</a></li> {% endfor %} </ul> </div> {% endif %} {% endfor %}
you need use square bracket notation instead of dot notation.
create string containing variable name (with assign or capture), use square bracket notation access setting name.
for example:
{% capture var %}footer_quicklinks_enable_{{i}}{% endcapture %} {% if settings[var] %} also see this similar answer.
Comments
Post a Comment