About collection output in metaobjects

Elvin_s
Shopify Partner
10 0 1

I have a metaobject,  One of the metafields (product.collection) saves collection (multiple).

 

The output using {{ shop.metaobjects.product.cd.collection }} is:  

["gid://shopify/Collection/299726864481","gid://shopify/Collection/301437452385"]

 

But I need like this "299726864481, 301437452385"

 

Can someone tell me how to filter ?

Replies 3 (3)
PaulNewton
Shopify Partner
5931 537 1241

Try .value {{ shop.metaobjects.product.cd.collection.value }}

Otherwise remove filter {{ shop.metaobjects.product.cd.collection | remove:"gid://shopify/Collection/" }}

 

If it needs to be looped over

{% assign cd_collection_ids = "" %}
{% for id in shop.metaobjects.product.cd.collection %}
 {% assign cd_collection_ids = cd_collection_ids | append: id | append:"," %}
{% endfor %}
{{ cd_collection_ids | remove_last:"," | remove:"gid://shopify/Collection/" }}

{% assign cd_collection_ids = cd_collection_ids | remove_last:"," | remove:"gid://shopify/Collection/" %}

 

To turn back into an array {% assign cd_collection_ids  = cd_collection_ids | split:"," %}

 

Save time & money ,Ask Questions The Smart Way


Confused? Busy? Get the solution you need paull.newton+shopifyforum@gmail.com


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Buy Paul a Coffee for more answers or donate to eff.org


Elvin_s
Shopify Partner
10 0 1

Thank you,

.value is invalid, This is one of the many approaches I've tried. 

remove filter is ok,I'm actually looking for a simpler and more straightforward filter, Just like in some cases, you can directly use .value to output the results.

Because I have obsessive-compulsive disorder 🙂

PaulNewton
Shopify Partner
5931 537 1241

Possibly the " | map " filter, but there needs to be a property on the object to map too.

Save time & money ,Ask Questions The Smart Way


Confused? Busy? Get the solution you need paull.newton+shopifyforum@gmail.com


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Buy Paul a Coffee for more answers or donate to eff.org