有没有办法连接两个字符串,然后在 Output 标签内处理结果而不是字符串?

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

这是我想要完成的:

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

渲染后我得到:

background-color: settings.collection_color_1;

而不是从 settings_data.json 获取的实际颜色,看起来像这样:

{
  "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"
    }
  }
}

有没有办法以编程方式完成此操作,或者我真的必须使用 <% case forloop.index %> 吗?

看看我对 的回答。

试试这个:

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