【问题标题】:Conditional formatting on Shopify snippet based on template file基于模板文件的 Shopify 代码段的条件格式
【发布时间】:2021-05-14 18:01:11
【问题描述】:

我的 Shopify 产品页面中有一个块,它在名为 product-page-1-description.liquid 的 sn-p 中声明了产品可用性,它传递了一些文件以到达 product-template.liquid。我的问题是礼品卡也使用此文件来显示产品信息,我需要特别删除/隐藏它们的可用性行。

这是我的问题:我可以根据调用文件的模板(礼品卡/产品)运行液体条件来显示/隐藏此块吗?仅仅创建一个全新的 sn-p 似乎很浪费。谢谢!

#product-page-1-description.liquid

 {%- if item.show_product_main_info -%}
  <div class="tt-add-info">
    <ul>
      {%- if item.show_quantity -%}
      <li class="availability">
        <span>{{ 'products.product.availability' | t }}</span>
        {% if product.available %}
        <span class="stock_quantity hide"></span> <span class="in_stock hide">{{ 'products.product.in_stock' | t }}</span> <span class="many_in_stock hide">{{ 'products.product.many_in_stock' | t }}</span> <span class="sold_out hide">{{ "products.product.sold_out" | t }}</span> <span class="continue_out hide">{{ "products.product.purchase_when_out_of_stock" | t }}</span>
        {% else %}
        <span class="sold_out">{{ "products.product.sold_out" | t }}</span>
        {% endif %}
      </li>
      {%- endif -%}
    </ul>
  </div>

【问题讨论】:

  • 我认为您可以使用 product.type 或简单地添加自定义标签来确定当前是哪种产品。
  • 或检查类似的内容{% if template contains 'gift_card' %}{% endif %}

标签: conditional-statements shopify liquid shopify-template


【解决方案1】:

当您从templates/gift_card.liquid 调用product-page-1-description.liquid 时,添加一个变量调用giftCard

{% include 'product-page-1-description.liquid', giftCard: true %}

如果有演出,请检查情况

 {%- if item.show_product_main_info -%}
      <div class="tt-add-info">
        <ul>
          {% unless giftCard %}
              {%- if item.show_quantity -%}
              <li class="availability">
                <span>{{ 'products.product.availability' | t }}</span>
                {% if product.available %}
                <span class="stock_quantity hide"></span> <span class="in_stock hide">{{ 'products.product.in_stock' | t }}</span> <span class="many_in_stock hide">{{ 'products.product.many_in_stock' | t }}</span> <span class="sold_out hide">{{ "products.product.sold_out" | t }}</span> <span class="continue_out hide">{{ "products.product.purchase_when_out_of_stock" | t }}</span>
                {% else %}
                <span class="sold_out">{{ "products.product.sold_out" | t }}</span>
                {% endif %}
              </li>
              {%- endif -%}
            {% endunless %}
        </ul>
      </div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-02
    • 2010-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-01
    相关资源
    最近更新 更多