Skip to content
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

Unexpected behavior when using reversed and limit on for..in loop #312

Closed
pdehaan opened this issue Feb 18, 2021 · 3 comments
Closed

Unexpected behavior when using reversed and limit on for..in loop #312

pdehaan opened this issue Feb 18, 2021 · 3 comments

Comments

@pdehaan
Copy link
Contributor

pdehaan commented Feb 18, 2021

Found in liquidjs@v9.23.0 (via @11ty/eleventy@canary).

I noticed that when using a for..in loop with the reversed and limit attributes, it always seems to apply limit first (so I only get items "one" and "two", regardless of which order I define reversed and limit:2):

{% assign arr = "one,two,three,four,five" | split: "," %}

{% for item in arr reversed limit: 2 %}
- {{ item }}
{% endfor %}

{% comment %}
OUTPUT
- two
- one
{% endcomment %}

In this case, I expected reversed to get applied first so limit:2 would pluck items "five", and "four", respectively.


Workaround seems to be to define "reverse" filter in the {% assign %} tag instead of in the for..in loop:

{% assign arr = "one,two,three,four,five" | split: "," | reverse %}

{% for item in arr limit: 2 %}
- {{ item }}
{% endfor %}

{% comment %}
OUTPUT
- five
- four
{% endcomment %}
@harttle
Copy link
Owner

harttle commented Feb 18, 2021

It seems intentional in shopify/liquid, but I'm considering add an option to enhance the behaviour, and merge this PR as well.

harttle pushed a commit that referenced this issue Sep 30, 2021
@harttle harttle closed this as completed Sep 30, 2021
harttle pushed a commit that referenced this issue Sep 30, 2021
github-actions bot pushed a commit that referenced this issue Sep 30, 2021
# [9.26.0](v9.25.1...v9.26.0) (2021-09-30)

### Features

* orderedFilterParameters, closes [#312](#312) ([10e8c8f](10e8c8f))
* stream rendering, closed [#361](#361) fixes [#360](#360) ([9012133](9012133))
* timezoneOffset option to specify output timezone, see [#375](#375) ([6b9f872](6b9f872))

### Performance Improvements

* improve performance by 4x by simplified parseFile ([24f5346](24f5346))
* parse filenames in parse() insteadof render() ([8273c17](8273c17))
@github-actions
Copy link

🎉 This issue has been resolved in version 9.26.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@harttle
Copy link
Owner

harttle commented Sep 30, 2021

Now can be enabled by setting orderedFilterParameters option to true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants