Can't getting collection name and image using collection id

I want to create custom menu of collections with the collection images.

Using childlink.object.id, I received collection id then I used this following method given below-

{%- assign collection = collections[childlink.object.id] %}

But no collection is retrieving using this method. childlink.object.id is giving me correct collection id but still can’t getting properties of the collection in navigation.liquid file.

Help me to resolve this issue. If you have any other method to retrieve collection using collecti

1 Like

Hi @HarpreetKourA ,

You don’t need to declare with collections.

You can get it directly e.g. get image collection: link.object.featured_image

Hope it helps!

1 Like

Hi @HarpreetKourA

I do not think collections with S have an object id. However, you can probably try the following code below to call the collection with an ID. See more information here.

I am curious if there is such variable childlink.object.id, never seen it before

{% for collection in collections %}
{%- assign collection = collections[childlink.object.id] %}
{% endfor %}

Please don’t forget to Like and Mark Solution to the post that helped you. Thanks!

Hi @HarpreetKourA
Please try this

{%- assign collection = childlink.object %}

To access the collection and then you can use collection.featured_image to fetch the featured image
Thanks!

1 Like

https://shopify.dev/docs/api/liquid/objects/link#link-object

It’s an old thing mainly because of how many old hacks used the navigation system as a data structure. Along with https://shopify.dev/docs/api/liquid/objects/link#link-type

So object.id is just a standing in for product.id, collection.id or any other property an object may have.

The collections (s , plural) requires a string handle https://shopify.dev/docs/api/liquid/objects/collections

So that forloop doesn’t work mainly because the assignment isn’t using anything from the forloop itself.

To get an object by an arbitrary id you have to either just loop over all that objects of that type and do a property match, or try to filter it down with array filters:

UNTESTED “collections” is an object not an array so may fail, and off the top of my head don’t remember how this interacts with more than 50 collections

{% assign collection_by_id = collections | where: 'id', childlink.object.id | first %}