如果符合某些条件,如何在Shopify产品页面上隐藏标签?

时间:2018-02-23 12:52:18

标签: shopify liquid

液体逻辑正在计算最高分(标记)并在产品页面上输出结果。但是,相同的分数列表(标签)也会显示在页面的其他位置。我希望能够在分数列表中隐藏最高分,因为这已经显示在一个单独的框中。

这是我计算得分最高的逻辑:

{%- 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 %}

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

{% 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 %}
相关问题