Here's 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 gets rendered I get:
background-color: settings.collection_color_1;
instead of the actual color fetched 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 accomplish this programmatically, or do I really have to use <% case forloop.index %> ?
Take a look at my answer to this similar question.
Try this:
{% assign color_from_settings = 'collection_color_' | append:forloop.index %}
...
{{ settings[color_from_settings] }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With