Is there a way to concatenate two lines and then process the result inside the Output tags not as a string?

Here is what I am trying to accomplish:

<ul class="site-nav__dropdown"> {% for childlink in linklists[child_list_handle].links %} this - {% assign color_from_settings = 'settings.collection_color_' | append: forloop.index %} used here - <li{% if childlink.active %} class="site-nav--active" {% else %} style="background-color: {{ color_from_settings }}" {% endif %}> <a href="{{ childlink.url }}" class="site-nav__link">{{ childlink.title | escape }}</a> </li> {% endfor %} </ul> 

When this happens, I get:

 background-color: settings.collection_color_1; 

instead of the actual color obtained from settings_data.json, which looks like this:

 { "current": "Default", "presets": { "Default": { ... "collection_color_1": "#9997c0", "collection_color_2": "#8997b1", "collection_color_3": "#7997a2", "collection_color_4": "#699793", "collection_color_5": "#599784", "collection_color_6": "#499775", "collection_color_7": "#399766", "collection_color_8": "#299757", "collection_color_9": "#199748", "collection_color_10": "#099739" } } } 

Is there a way to do this programmatically or do I really need to use <% case forloop.index%>?

+6
source share
1 answer

Take a look at my answer to this similar question .

Try the following:

 {% assign color_from_settings = 'collection_color_' | append:forloop.index %} ... {{ settings[color_from_settings] }} 
+12
source

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


All Articles