Why isn't my custom liquid vendor link always clickable?

Hi

I’ve added custom liquid to my product page (below)

with the aim of making a clickable link to show the relevant vendor (brand)

this works for most of my products , but doesn’t seem to be clickable for others (see images)

Wildfox - not clicking

kokomo - clickable

can anyone help as to why?

{% for collection in collections %}> {% if collection.title == product.vendor %}> {% assign brand_link = collection.url %}> {% break %}> {% endif %}> {% endfor %}> > {% if brand_link %}> {{ product.vendor }}> {% else %}> {{ product.vendor }}> {% endif %}> >

> >

You’ve made some good digging to understand what code you might need but the code is flawed. Let’s break it down.

{% for collection in collections %}
{% if collection.title == product.vendor %}
{% assign brand_link = collection.url %}
{% break %}
{% endif %}
{% endfor %}

Depending on how many collections you have that loop will not cover everything. There’s a max limit to the amount of collections you should expect to get returned in a Collections drop (1000). Looking at the shop noted in your image you are likely hitting that. Your /collections page shows the max of 1000 collections so guessing you have far more than that.

And knowing the collection starting with W is one missed and K is not it does add some weight to my assumptions here.

What this means is the loop is stopping before it’s look at every collection. By the time it gets to this code…

{% if brand_link %}
<em><a href="{{ brand_link }}">{{ product.vendor }}</a></em>
{% else %}
<em>{{ product.vendor }}</em>
{% endif %}

…brand_link won’t have had a value set.

It’s a very inefficient loop in any case so there’s a better way to do it.

If your vendor name handleized matches the collection name handle you could just reference the collection directly, grab the url, and skip the loop entirely.

Thanks , could you help with what code I should use?

something like:

{%- assign vendorHandle = product.vendor | handleize -%}
{%- if collections[vendorHandle].products.size > 0 -%}
*{{ product.vendor }}*
{%-  endif -%}

Now this assumes that the vendor title converted to a handle will match whatever handle you’re using for the collection.

Amazing thanks so much

Im noticing the same issue with my vendor collection page I have made :

https://spoiledbrat.co.uk/pages/brandlist-a-z

The last 12 on the list seems to be showing all products rather than brand collection I have made

Would you be able to help?

Here is the code I have used

}

.page-content-max a {
color: #ff1493;
text-decoration: none;
transition: color 100ms cubic-bezier(0.4, 0, 0.2, 1);
}

.vendor-list {
-webkit-columns: 3; /* Chrome, Safari, Opera /
-moz-columns: 3; /
Firefox /
columns: 3;
}
@media (max-width: 640px) {
.vendor-list {
-webkit-columns: 1; /
Chrome, Safari, Opera /
-moz-columns: 1; /
Firefox */
columns: 1;
}
}

{% if page.content != blank %}

{{ page.content }}

{% assign counter = 0 %}
{% for vendor in shop.vendors %}
{% assign counter = counter | plus: 1 %}
{% endfor %}

{% assign counter_divided_by_3 = counter | divided_by: 3 | floor %}

    {% for product_vendor in shop.vendors %} {% assign its_a_match = false %} {% capture my_collection_handle %} {{ product_vendor | handleize | strip | escape }} {% endcapture %} {% assign my_collection_handle_stripped = my_collection_handle | strip | escape %}

    {% for collection in collections %}
    {% if my_collection_handle_stripped == collection.handle %}
    {% assign its_a_match = true %}
    {% endif %}
    {% endfor %}

    {% if its_a_match %}

  • {{ product_vendor }}
  • {% else %}
  • {{ product_vendor | link_to_vendor }}
  • {% endif %} {% endfor %}
{% endif %}

Hi Jason,

I’m exactly looking for that function - make the vendor’s name clickable to its collection-, but I’m not sure where to copy this code precisely?

Thank you by advance!

Emmanuelle