简体   繁体   English

如何在单独的标签中显示Shopify产品项变体?

[英]How can I display a Shopify product item variant in seperate tags?

Using the following displays the variant as one item. 使用以下命令将变体显示为一项。 Example. 例。 Size and colour display as <li>small/red</li> 尺寸和颜色显示为<li>small/red</li>

{% unless item.product.has_only_default_variant %}
    <li>{{ item.variant.title }}</li>
{% endunless %}

I'd like to display 我想展示

  • size: small 尺寸:小
  • colour: red 颜色:红色
  • Is this possible in Liquid/ shopify? 在Liquid / shopify中这可能吗?

    You will not be able to retrieve variant's option name like "size" or "colour" from variant's object. 您将无法从变量的对象中检索变量的选项名称,例如“大小”或“颜色”。 Maybe you might try something different like this (not tested): 也许您可以尝试类似的方法(未经测试):

    {% for option in product.options %}
      {% case forloop.index %}
        {% when 1 %}
        {% assign option_name1 = option.name %}
        {% when 2 %}
        {% assign option_name2 = option.name %}
        {% when 3 %}
        {% assign option_name3 = option.name %}
      {% endcase %}
    {% endfor %}
    

    And then: 接着:

    {% for variant in product.variants %}
      {% if variant.option1 %}
        <p>{{ option_name1 }}: {{ variant.option1 }}</p>
      {% endif %}
      {% if variant.option2 %}
        <p>{{ option_name2 }}: {{ variant.option2 }}</p>
      {% endif %}
      {% if variant.option3 %}
        <p>{{ option_name3 }}: {{ variant.option3 }}</p>
      {% endif %}
    {% endfor %}
    

    声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

     
    粤ICP备18138465号  © 2020-2024 STACKOOM.COM