Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
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
Solved! Go to the solution
This is an accepted solution.
To get what you need you should use .value -- this way you will get collection object from the collection field.
{{ brand.name }} <br/>
{{ brand.collection.value.url }} <br/>
produces:
My brand
/collections/all
Technically, you should also use brand.name.value, but for text line system stores just the text. However for collection it stores the id.
Using .value allows you to fetch corresponding collection object and then use it's properties.
This is an accepted solution.
To get what you need you should use .value -- this way you will get collection object from the collection field.
{{ brand.name }} <br/>
{{ brand.collection.value.url }} <br/>
produces:
My brand
/collections/all
Technically, you should also use brand.name.value, but for text line system stores just the text. However for collection it stores the id.
Using .value allows you to fetch corresponding collection object and then use it's properties.
Legend Tim, thanks for clearing that up for me. Many Thanks!
Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024In today’s interview, we sat down with @BSS-Commerce to discuss practical strategies f...
By JasonH Nov 13, 2024