Liquid, JavaScript, themes, sales channels
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 %}
<div class="brandlist_card"
{% if add_anchor %} id="{{ vendor | slice:0 }}"{% endif %}
>
{{ vendor }}
</div>
{% endfor %}
Result:
<div class="brandlist_card" id="A">AAA</div>
<div class="brandlist_card" id="A">AAB</div>
<div class="brandlist_card" id="A">ABC</div>
<div class="brandlist_card" id="B">BBB</div>
<div class="brandlist_card" id="C">CCC</div>
Actually, I expect that the result should be as below:
<div class="brandlist_card" id="A">AAA</div>
<div class="brandlist_card">AAB</div>
<div class="brandlist_card">ABC</div>
<div class="brandlist_card" id="B">BBB</div>
<div class="brandlist_card" id="C">CCC</div>
[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 %}
User | RANK |
---|---|
37 | |
24 | |
13 | |
13 | |
9 |
Transform this holiday season into a shopping spree. Plus, learn how to effortlessly open ...
By Jasonh Dec 8, 2023Make the shift from discounts to donations, and witness your business not only thrive fina...
By Holly Dec 4, 2023On our Shopify Expert Marketplace, you can find many trusted third party developers and fr...
By Arno Nov 27, 2023