Shopify / Shopify/liquid

Add where/reject option to for

Open
#1,593 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Feature Request
Dominant language
Ruby
Stars
11.9k
Forks
1.5k
Avg merge
17h 55m
Merged PRs (30d)
3

Description

Hi,

In Shopify, we often need to loop through blocks and ignore some depending on conditions. It would be very handy if for loops would support an extra "where" and "reject" filters:

{%- for block in section.blocks where: 'settings.image' -%}
  Only loop through blocks whose image is defined 
{%- else -%}
  Show placeholder
{%- endfor -%}

This would make the syntax much more expressive and would remove a lot of useless creation of temporary variables (which are often source of hard to track bug when they override already existing variables).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating Liquid's existing for-loop implementation and tests, then compare how the proposed where filter would interact with section.blocks and the existing else branch. Define the behavior and syntax for both where and reject, including the settings.image example, and consider the feature complete when filtered loops and empty-result handling are covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.