Shopify:当没有定义尺寸时,在liquid模板中隐藏尺寸变量标题

Shopify:当没有定义尺寸时,在liquid模板中隐藏尺寸变量标题,shopify,liquid,shopify-template,Shopify,Liquid,Shopify Template,我正在使用Shopify,如果没有为产品定义尺寸,我想在模板中隐藏尺寸变量标题 下面是我的商店中呈现的代码的屏幕截图 以下是我的liquid模板中的代码片段: <div class="options clear"> {% if product.available %} <div class="product-info-row"> <div class="product-info-col1"> <h4>Quantity</h4>

我正在使用Shopify,如果没有为产品定义尺寸,我想在模板中隐藏尺寸变量标题

下面是我的商店中呈现的代码的屏幕截图

以下是我的liquid模板中的代码片段:

<div class="options clear">
{% if product.available %}
<div class="product-info-row">
  <div class="product-info-col1">
    <h4>Quantity</h4>
    <div class="quantity">
      <div class="quantity-display">1</div>
      <input name="quantity" type="hidden" value="1" data-max="{{product.selected_or_first_available_variant.inventory_quantity}}">
      <div class="quantity-decrement">-</div>
      <div class="quantity-increment">+</div>
    </div>
  </div>
  {% if product.variants.size >= 1 %}
  <div class="product-info-col2">
    <h4>Size</h4>
    <div class="variants">
      {% unless product.selected_or_first_available_variant.title contains "Default" %}
      <ul class="variant-list">
        {% for variant in product.variants %}
        {% if variant.available %}
        <li class="{% if variant == product.selected_or_first_available_variant %} selected{% endif %}" data-value="{{ variant.id }}" data-quantity="{{ variant.inventory_quantity }}"> {{ variant.title }}</li>
        {% endif %}
        {% endfor %}
      </ul>
      {% endunless %}
    </div>
  </div>
  {% endif %}
  <input type="hidden" class="variant-id" name="id" value="{{product.selected_or_first_available_variant.id}}">
</div>
{% endif %}

我有点困惑,因为HTML中已经存在大小变量的运算符逻辑:{%if product.variants.size>=1%}。此产品没有定义大小的变体0小于1,那么,为什么此大小变体的HTML块仍然显示?任何帮助都将不胜感激。谢谢大家!

Shopify中的每个产品至少包含一个变体。您的条件{%if product.variants.size>=1%}为真。但是{%除非product.selected\u或\u first\u available\u variant.title包含默认值%}为false


为了更好地理解产品对象,我建议您将{{product | json}}添加到液体中,以将所有对象呈现为序列化的json。这将使您更好地了解产品对象及其字段

非常感谢。只需将{%inspect product.selected_或{u first_available_variant.title包含Default%}向上移动几行就可以完成我所需要的操作。是的,你说得对。那会解决你的问题。但我仍然建议,如果您将来会感到困惑,请查看产品对象