一个液体逻辑正在计算最高分(标签)并在产品页面上输出结果。但是,页面上的其他地方也显示了相同的分数(标签)列表。我希望能够隐藏分数列表中的最高分,因为这已经显示在单独的框中。
这是我计算最高分的逻辑:
{%- 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 %}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句