How can I filter collection output in metaobjects?

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 ?

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:“,” %}

1 Like

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 :slightly_smiling_face:

1 Like

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