I have created a Metaobject called brands. It has a title, description, image and a collection reference. There is a screenshot of the Metaobject below.
I have included the current code I’m using below. Essentially I’m trying to output the collection link for the selected collection in the Metaobject entry to use for the a href. However all I seem to be able to output is the collection ID using the code I have or just gid://shopify/Collection/628469498189 for example using {{ brand.collection }}.
I need to be able to output the collection handle for the selected collection, not the id. Is this possible? Nobody in Shopify support seems to be able to help.
<section class="brands-list">
<div class="brands-grid">
{% for brand in shop.metaobjects.brands.values %}
<div class="brand-item">
{% if brand.collection %}
{% assign collection_handle = brand.collection | split: '/' | last %}
<a href="/collections/{{ collection_handle }}" class="brand-link">
{% endif %}
<img
src="{{ brand.logo | image_url: width: 400 }}"
alt="{{ brand.title }}"
class="brand-logo">
{% if brand.collection %}
</a>
{% endif %}
<h3 class="brand-title">{{ brand.title }}</h3>
</div>
{% endfor %}
</div>
</section>
Many Thanks,
Roo
