Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
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 %}
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025