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!