Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

shopify

liquid

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 %> ?

like image 348
Jared Tomaszewski Avatar asked May 09 '15 22:05

Jared Tomaszewski


1 Answers

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] }}
like image 98
Steph Sharp Avatar answered Oct 31 '22 01:10

Steph Sharp