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

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -