Thanks in advance.
Object: shop.vendors
vendors: AAA, AAB, ABC, BBB, CCC
{% assign temp_vendor = “” %}
{% assign add_anchor = false %}
{% for vendor in shop.vendors %}
{% if temp_vendor != vendor | slice: 0 %} ← How come this statement always be true?
{% assign temp_vendor = vendor | slice: 0 -%}
{%- assign add_anchor = true %}
{% else %}
{%- assign add_anchor = false %}
{% endif %}
{{ vendor }}
{% endfor %}
Result:
Actually, I expect that the result should be as below:
[loop 1]
vendor is “AAA”.
add_anchor = false
temp_vendor = “”
When temp_vendor NOT EQUAL “AAA”
temp_vendor “AAA” | slice: 0
temp_vendor = “A”
assign add_anchor → true
[loop 2]
vendor is “AAB”
temp_vendor = “A”
vendor | slice: 0 (“A”)
{% if temp_vendor != vendor | slice: 0 %}
The above statement should be FALSE since “A” != “A”.
How come “A” !=“A” is TRUE?
The next step should be:
{%- assign add_anchor = false %}
Instead of:
{% assign temp_vendor = vendor | slice: 0 -%}
{%- assign add_anchor = true %}