Collection pages filter products with where_exp. The expression works when it compares against a literal, but as soon as it mentions another variable, one set with assign or passed in by the page, that variable is empty…
Collection pages filter products with where_exp. The expression works when it compares against a literal, but as soon as it mentions another variable, one set with assign or passed in by the page, that variable is empty inside the expression and nothing matches. group_by_exp and find_exp have the same problem.
products holds four products: Vacuum (type house, price 120), Spatula (kitchen, 8), Television (lounge, 400) and Garlic press (kitchen, 15).
{% assign target = "kitchen" %}{{ products | where_exp: "item", "item.type == target" | map: "title" | join: ", " }}.{% assign found = products | find_exp: "item", "item.price > min" %}{{ found.title }} with min set to 100.{% for t in types %}{{ t }}={{ products | where_exp: "p", "p.type == t" | size }};{% endfor %} with types set to ["kitchen", "house", "garden"].Spatula, Garlic pressVacuumkitchen=2;house=1;garden=0;kitchen=0;house=0;garden=0;where_exp: "item", "item.type == 'kitchen'" returns both kitchen products.assign and capture values, and loop variables.Adapted from harttle/liquidjs (MIT).
Visible test command
TZ=UTC npx --no-install jest --ci --coverage=falseThe repository’s own tests. Run all tests includes them, and so does every submission.
Repository
expression-filters-cannot-see-variables
Changes under src/ are evaluated.