-
-
Notifications
You must be signed in to change notification settings - Fork 231
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
Fix: respect parameter order when using "for ... reversed" #231
Conversation
I'm afraid it's not conformant which means it'll break Jekyll sites and Shopify templates, though I absolutely like this point. Try file an issue on https://github.com/Shopify/liquid instead. |
@harttle thanks for the quick feedback! It looks like this was proposed 5+ years ago but fizzled out. I added my voice to the issue with yet another suggestion to extend |
BREAKING CHANGES: - previously deprecated `getTemplate()` and `getTemplateSync()` not no longer supported - `opts` no longer support dynamic set in `parseFile()`, `renderFile()` arguments
Added {% for i in (1..8) offset:2 reversed limit:3 %}{{ i }}{% endfor %} expected value from And there's a strange behavior, which I consider it as a bug, in Shopify liquid that {% for i in (1..8) offset:2 reversed %}{{ i }}{% endfor %} yields {% for i in (1..8) reversed offset:2 %}{{ i }}{% endfor %} yields |
* fix: spelling * fix: respect param order for reversed * docs: add for-reversed order details * perf: improve performance by 4x by simplified parseFile BREAKING CHANGES: - previously deprecated `getTemplate()` and `getTemplateSync()` not no longer supported - `opts` no longer support dynamic set in `parseFile()`, `renderFile()` arguments * perf: parse filenames in parse() insteadof render() * docs: update description of LiquidJS Co-authored-by: harttle <yangjvn@126.com>
With regards to the
for
tag's reversed parameter, I found the current behavior of reversing a collection after all the other parameters execute a bit unexpected (and not very useful).Given
{% for i in (1..8) reversed limit: 4 %}{{ i }}{% endfor %}
, I would expect the params are executed from left to right. In other words, the collection is reversed first and then limited to four items with an output of8765
.Instead I get
4321
, which is what I would expect with{% for i in (1..8) limit: 4 reversed %}{{ i }}{% endfor %}
where the collection is limited to the first four items before reversing.My use case for this is reversing a large collection of blog posts (so they are listed as most recent first) and then sizing those results down to five posts for the home page.
This proposed change will impact existing code that uses
reversed
with additional params. If this PR seems too risky, perhaps adding a new parameter (flipped
?) with the proposed functionality would do the trick.