【问题标题】:Show variable outside for loop shopify在 for 循环 shopify 外显示变量
【发布时间】:2020-05-14 09:01:19
【问题描述】:

我试图在 for 循环之外的 Shopify 中显示所选值。 如何在“颜色:”之后的标签中显示选定的单选选项?我想将它显示在“显示选择的选项”的位置。

有人知道怎么解决吗?

<label>Color: SHOW SELECTED OPTION</label>

<fieldset class="single-option-color-selector"
  id="ProductSelect-option-{{ forloop.index0 }}">
  {% assign option_index = forloop.index %}
  {% for value in option.values %}
    {% assign variant_label_state = true %}
    {% if product.options.size == 1 %}
      {% unless product.variants[forloop.index0].available  %}
        {% assign variant_label_state = false %}
      {% endunless %}
    {% endif %}
    <input type="radio"
      {% if option.selected_value == value %} checked="checked"{% endif %}
      value="{{ value | escape }}"
      data-index="option{{ option_index }}"
      name="color"
      class="single-option-selector__radio"
      id="ProductSelect-option-{{ option.name | handleize }}-{{ value | escape }}">
    <label class="option-color-{{ value | escape }}" for="ProductSelect-option-{{ option.name | handleize }}-{{ value | escape }}" title="{{ value | escape }}">{{ value | escape }}</label>
  {% endfor %}
</fieldset>

【问题讨论】:

  • 我的回答有帮助吗?

标签: loops variables shopify liquid


【解决方案1】:

根据你分享的代码,你可以试试这个:

<label>Color: {{ option.selected_value }}</label>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-06
    • 1970-01-01
    • 1970-01-01
    • 2020-04-05
    • 1970-01-01
    • 2018-09-28
    相关资源
    最近更新 更多