-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
list.product_reference.size #1589
Comments
We are having the same issue. Plus, giving the array to the Size filter always returns 0, whether the size is 0 or not |
Having the same problem, can iterate over the array but If the product reference list metafield has never been used, i can check if it's nil: {% if product.metafields.custom.mylist == nil %} I've been unable to find a workaround for this. |
Is it that the "list" is only the storage of the data but the metafield is only storing string? maybe it only works with JSON.parse( product.metafields.custom.mylist)? |
This worked for me: {%- assign product_list = product.metafields.custom.mylist | split: ',' | uniq -%} |
Still running into this issue as well but with collection lists (metafield type |
upon till today this is still an issue, i.e. metafields of type {% assign productIngredients = product.metafields.custom.ingredient_details.value %}
{% assign productIngredientsArray = product.metafields.custom.ingredient_details | split: ',' %} // might want the uniq filter too
{% assign productIngredientsTotal = productIngredientsArray.size %} |
Using |
Interesting, It seems |
@annatwp solution worked for me |
This trick might work to get the size, but this prevents to access an object such as a product reference. I described the issue here: #1643 (comment) I really wonder why this is not fixed yet, very annoying that we can have list but can't navigate them with liquid array filters. |
@masserra use .value so artists.size.value |
I had tried Don't understand the why of using |
This is the only thing that worked for me to be able to use BUT... then all I get is an array of metaobject GID reference strings ( So... even though this was obviously a hack, this is definitely not the solution. |
Solution:OK!! Finally found the cleanest hack to make the array behave like an actual array, a double To come back to my real world example would look like: Key points that need to be reviewed:
|
Note to the Shopify Liquid Team:It's almost been 1 year since this issue has been opened, everywhere I look I see people struggling not only with the use of The longer this goes on unsolved the more codebases might end up having a breaking change once you finally tackle the issue.. |
I can't believe your solution is actually working!! Great finding @masserra You nailed it. So something like this is now possible:
A standard for loop works normally as well, but in some situations it is not a practical way to code:
I can't agree more with you with the issues you highlighted. Shopify simply ignores us here, I don't mean to be rude or offensive, but why did they not address this at least once, it is puzzling... As for the metafields Now, I wonder if this "trick" is a good idea for production. Could it not backfire? As long as there is no breaking change introduced (which is something I've never seen Shopify do yet), I don't mind using this trick, this can make code simpler and cleaner. |
@MaxDesignFR 🙌 🙌 Thank you for that liquid doc, it completely escaped me. Although, what I also mean by "unintuitive" is that JSON stringifying the object doesn't expose the correct tree structure, it suggests that the list can be accessed straight away and that no other attribute (value) needs to be used to access the list 1 more step down the tree. I spoke to a Shopify admin on discord and they said it's all about priorities as they have many other higher important issues to tackle, which I understand actually, they've indeed been pushing quite a lot of new exciting features lately 🫶 In regards to being production ready I don't see why it might not be. I'll choose this one over any other solution (for now) as this one at least is a clean & explicit hack that feels familiar to other devs and doesn't go around the problem too much, a simple comment and every dev will be in sync. Plus it enables us to use only Shopify's documented liquid standards and no undocumented ones such as |
If size is 0 then I try count. Seems to be working for me. |
We have a metaobject that has a field that accepts products (list) and this is how I solved the counting issue:
|
{{ metafields.custom.array.value.count }} worked for me, God knows why. |
I can confirm that .count worked for me where .size did not... Really annoying that they don't let you json print objects or really debug in anyway to find this out on our own. |
This issue is now 2 years old, and while @masserra's hack works... I'd much rather not have to keep relying on workarounds for liquid's incompetencies. |
I've been struggling with this for going on the time that file 'list' metafields have been a thing to allow clients to upload multiple images and I've finally found this after 2/3 years. |
Ouch, that must have stung! It is a handy workaround. Definitely don’t miss that issue, it's been around for 11 years, but I'm sure they're all over it (I swear, I’m not delusional). If it ever gets resolved, it may change your liquid game and your life to some extent. Serious liquid fun right there. |
Still an issue! |
I have a custom metafield of a product list.
When I display the list {{ product.metafields.custom.mylist }}
["gid://shopify/Product/7668926775542","gid://shopify/Product/7491343778038"]
but
{{ product.metafields.custom.mylist.size }}
shows nothing
is list !== array?
The text was updated successfully, but these errors were encountered: