Adding a new "where" filters
Hi,
The where filter is very useful, but I would suggest having a few improvements:
where_not
This filter would do the opposite of where filter:
{% assign blocks_to_render = section.blocks | where_not: 'type', 'divider' %}
Allow dot notation
With metafields and dynamic connection, it is increasingly common that merchant create a section with blocks, and bound the content with metafields.
For instance, let's imagine a "testimonials" section where the merchant would create 5 blocks. Some products may have 5, 4, 3, 2 or even no active blocks, depending on the product. This currently makes rendering very cumbersome. I would love having a dot notation. For instance:
{% assign rendered_blocks = section.blocks | where: 'settings.testimonial' %}
{% assign rendered_blocks = section.blocks | where: 'settings.product' %}
The idea here is to return actual block instances, but that would be filtered. This would allow to generate section code based on the actual content indicated by the merchant.
A PR for dot notation in where filter is open here https://github.com/Shopify/liquid/pull/1436
I'd recommend calling the inverse of where reject, as that maps to the identical feature in Ruby.
Is there any update on this? I know it's been 1 year without a reply, but it's still relevant and would be an insane help to have on Shopify :)
where_not is really required! There is no way to filter for nested properties that are not empty!
This filters section blocks where row_content is empty:
{% assign blocks = section.blocks | map: 'settings' | where: 'row_content', empty %}
There is absolutely no way to filter blocks where row_content is not empty!