如果满足特定条件,如何在 Shopify 产品页面上隐藏标签?
How to hide a tag on a Shopify product page if certain condition is met?
液体逻辑正在计算最高分(标签)并将结果输出到产品页面。但是,相同的分数(标签)列表也显示在页面的其他地方。我希望能够隐藏分数列表中的最高分数,因为它已经显示在一个单独的框中。
这是我计算最高分的逻辑:
{%- capture list_of_scores -%}
{{wa}}|Wine Advocate,
{{bh}}|Burghound,
{{ag}}|Vinous,
{{jr}}|Jancis Robinson,
{{jg}}|John Gilman
{%- endcapture -%}
{%- capture list_of_scores_num -%}
{{wa}},
{{bh}},
{{ag}},
{{jr}},
{{jg}}
{%- endcapture -%}
{% assign scores_array = list_of_scores | split: ',' %}
{% assign scores = list_of_scores_num | split: ',' %}
{% assign highest_score = scores | first | plus: 0 %}
{% assign name = '' %}
{% for score_val in scores %}
{% assign cur_score = score_val | plus: 0 %}
{% if cur_score >= highest_score %}
{% assign highest_score = score_val | plus: 0 %}
{% assign name = scores_array[forloop.index0] | split: '|' | last %}
{% endif %}
{% endfor %}
<span>{{ highest_score }}</span>
<h5>{{ name }}</h5>
我试过这个来隐藏列表中最高的标签:
{% if wa != highest_score %}<span>WA {{ wa }}</span>{% endif %}
有什么建议吗?
{% if wa != highest_score %}
这个条件永远成立,因为看起来 wa
是一个字符串而 highest_score
是一个整数(因为 | plus: 0
用于转换字符串为整数)。整数不能等于字符串。
您也可以尝试将 wa
转换为整数,然后将其与 highest_score
进行比较:
{% assign waToInt = wa | plus: 0 %}
{% if waToInt != highest_score %}<span>WA {{ wa }}</span>{% endif %}
液体逻辑正在计算最高分(标签)并将结果输出到产品页面。但是,相同的分数(标签)列表也显示在页面的其他地方。我希望能够隐藏分数列表中的最高分数,因为它已经显示在一个单独的框中。
这是我计算最高分的逻辑:
{%- capture list_of_scores -%}
{{wa}}|Wine Advocate,
{{bh}}|Burghound,
{{ag}}|Vinous,
{{jr}}|Jancis Robinson,
{{jg}}|John Gilman
{%- endcapture -%}
{%- capture list_of_scores_num -%}
{{wa}},
{{bh}},
{{ag}},
{{jr}},
{{jg}}
{%- endcapture -%}
{% assign scores_array = list_of_scores | split: ',' %}
{% assign scores = list_of_scores_num | split: ',' %}
{% assign highest_score = scores | first | plus: 0 %}
{% assign name = '' %}
{% for score_val in scores %}
{% assign cur_score = score_val | plus: 0 %}
{% if cur_score >= highest_score %}
{% assign highest_score = score_val | plus: 0 %}
{% assign name = scores_array[forloop.index0] | split: '|' | last %}
{% endif %}
{% endfor %}
<span>{{ highest_score }}</span>
<h5>{{ name }}</h5>
我试过这个来隐藏列表中最高的标签:
{% if wa != highest_score %}<span>WA {{ wa }}</span>{% endif %}
有什么建议吗?
{% if wa != highest_score %}
这个条件永远成立,因为看起来 wa
是一个字符串而 highest_score
是一个整数(因为 | plus: 0
用于转换字符串为整数)。整数不能等于字符串。
您也可以尝试将 wa
转换为整数,然后将其与 highest_score
进行比较:
{% assign waToInt = wa | plus: 0 %}
{% if waToInt != highest_score %}<span>WA {{ wa }}</span>{% endif %}