Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
I've attached a custom metafield to a subcollection, so i can attach it's parent collection to it like this:
Control Panels: (collection)
So on simplex, i have a metafield: custom.parentcollection
and this metafield type is a single 'Collection' (Control Panels)
Now on this Simplex Collection Page, when i try to retrieve that parent's collection title, i'm unable to, seemingly no matter what i try
Even If i do a direct search, placing the parent collection's ID directly into liquid like this:
{% assign parent_collection = collections[11197939740] %}
when i go to reference that variable with {{ parent_collection }}, {{ parent_collection.title }}, or anything of the sort, i'm getting nothing and idk why 😕
I'm running on the latest theme version of Empire from Pixel Union.. Any help is appreciated, thanks in advance 🙂
Hi Toplocations,
Sasha here from Metafields Guru.
The answer to your question. From the looks of it, you are working with a collection reference metafield. The payload returned by Liquid for this type of metafield is a collection object. Unfortunately, you can't use an object to grab the data from the global object/array in that way. Consider retrieving the ID from the object and then using it to access the data.
A friendly suggestion. It would help if you opted for a more efficient approach. As you can see from the above part of my reply, you already have access to the parent collection object thanks to the reference metafield, so you don't need to retrieve it from the "collections". It is a redundant step. Also, the global variables like all_products, collections, etc. are extremely time- and resource-consuming (which is bad for your storefront) and you should avoid using them unless you have no other option.
Hope this helps!
so going from the metaobject, i thought i'd retrieved the ID of it's collection like this:
{% assign collection_id = collection_reference | split: '/' | last %}
but that wasn't working here
{% assign parent_collection = collections[collection_id] %}
so that's why i pasted in the ID directly (thinking perhaps it wasn't retrieving it correctly), but even that still isn't working..
You're saying that using collections[collection_id] is redundant, but even if it try
{{ collection.metafields.custom.parentcollection.title }}
it doesn't load anything.. i'm just not understanding what i'm missing here 😕
Thanks for your time 🙂
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