liquid icon indicating copy to clipboard operation
liquid copied to clipboard

Nested search in where filter

Open andershagbard opened this issue 3 years ago • 5 comments

This PR allows nested search in where filter.

{% assign blocks = section.blocks | where: 'settings.some_setting' %}
{% assign blocks = section.blocks | where: 'settings.some_setting', 'blue' %}

Resolves #1388

andershagbard avatar May 04 '21 08:05 andershagbard

This would be really nice in sort, too. I have a date.start I'd like to sort by, and item.dig(*property.split('.', -1)) would work very well there too I'd think.

henryiii avatar May 20 '21 21:05 henryiii

This shouldn't bring any breaking changes to Shopify, but could bring breaking changes to other platforms using Liquid, as it won't consider attributes with dots.

I'm not sure if that is actually the case. Doesn't Shopify support JSON metafield types? If the where filter were used on some parsed json blob, then I would think it could end up filtering on keys with a period in them.

In that case, the input would be a string, and this filter shouldn't do anything then?

andershagbard avatar Sep 10 '21 06:09 andershagbard

I don't mean storing JSON in a string type field, I mean there is native support for JSON metafield types. The primary reason for that json type is so the parsed json is made accessible to liquid, meaning it could be arrays of hashes with keys that could have a period in it.

dylanahsmith avatar Sep 10 '21 14:09 dylanahsmith

I don't mean storing JSON in a string type field, I mean there is native support for JSON metafield types. The primary reason for that json type is so the parsed json is made accessible to liquid, meaning it could be arrays of hashes with keys that could have a period in it.

Got it. Should we cover that case?

andershagbard avatar Sep 10 '21 16:09 andershagbard

Does it make sense to add this nested feature to other filters, such as sort, uniq etc?

andershagbard avatar Oct 27 '21 19:10 andershagbard

Opened a new PR which solves this in a way better way: https://github.com/Shopify/liquid/pull/1749

andershagbard avatar Oct 18 '23 08:10 andershagbard