How do I access collection values from a GID in a template?

Topic summary

Goal: Use a collection reference (GID) stored in a product metafield to access collection properties (title, URL, images) within a Liquid template.

Key detail: The metafield is a collection reference type, so using .value on the metafield returns the actual Collection object, not just the GID string.

Solution:

  • Assign the metafield’s value to a variable:
    • {% assign mycollection = product.metafields[“details”][“mycollectionfield”].value %}
  • Access properties from the object:
    • mycollection.title, mycollection.url (and other collection attributes like images, metafields).

Outcome: The approach worked for the requester, who confirmed resolution.

Docs: A Shopify metafields documentation link was provided for further reference.

Status: Resolved; no outstanding questions. Another participant noted they learned that the GID-backed metafield resolves to an object in Liquid.

Summarized with AI on January 17. AI used: gpt-5.

Hi,

I can’t find the proper way to call / load the collection object from a GID.

I am trying to access collection values (Title / Metafields) in a template.

All I have available is a custom collection reference field:

product.metafields["details"]["mycollectionfield"]

containing a gid value:

gid://shopify/Collection/111111

And i would like to use this referenced collection in an object to access the values of the collection like Titles / Images and such.

I found another similar thread about a the product object. The solution said, it is required to assign the object to a variable, but I have not found the example code to do that with a collection reference metafield.

Would be great to be pointed to the documentation explaining the steps.

Hi @RetroShirtsMan ,
You can access the collection saved in a product meta field by first assigning the collection in a variable as shown in below code:

{% assign mycollection = product.metafields["details"]["mycollectionfield"].value %}
{% comment %} 
  {{ mycollection.title }} - returns collection title  
  {{ mycollection.url }} - returns collection URL 
{% endcomment %}

Please let me know if you need more help
Thanks

2 Likes

It works thank you very much. I will mark it as solved in a minute.

But might you provide me with the link to the documentation where I could have looked or found this myself? I tried hard and was not able to find it.

1 Like

Hey @RetroShirtsMan , I am glad that my solution worked for you.
Also you can refer to the below doc in order to explore more about metafields: https://shopify.dev/apps/metafields?shpxid=ecfb75a2-D7B0-43D5-F156-3616555F0B9F

Thanks

Thanks so much for this information on GID! I did not know it was an object like this!