Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
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.
Solved! Go to the solution
This is an accepted solution.
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
This is an accepted solution.
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
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.
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!
By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024