You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Author: Shopify Expected end date: December 5, 2024
Background
Today, the slice filter is limited to counting items from the start index, with no option to count backwards from the end. This creates unnecessary toil, affecting the developer experience, as seen in the following examples.
Inspired by slice operations in other languages, we propose supporting negative numbers in the second argument, making operations more intuitive by controlling the direction of elements being taken.
With this enhancement, that example becomes simpler and clearer:
This proposal is not currently backward compatible:
{{ fruits | slice:0, -2 }}
{% # => [] %}
Therefore, we will conduct an impact assessment to evaluate the feasibility and ensure a smooth transition if this change is implemented.
Call for suggestions
We welcome any feedback or opinions on this proposal. Please share your thoughts by December 5, 2024. Your input is valuable as we prepare to begin active development on this initiative.
The text was updated successfully, but these errors were encountered:
This seems low-risk since old themes wouldn’t use negatives, right?
Could possibly impact some custom codes, if they treat negative values as 0. Although I think the impact is minimal, as slice is rarely used from my experience.
{%- liquid # Count get assigned to -2assigncount = array.size | minus:5assignsliced_list = array | slice:0, count
Author: Shopify
Expected end date: December 5, 2024
Background
Today, the
slice
filter is limited to counting items from the start index, with no option to count backwards from the end. This creates unnecessary toil, affecting the developer experience, as seen in the following examples.It's straightforward counting from the index:
However, operations such as getting all array elements except the last two can become verbose:
Proposal
Inspired by
slice
operations in other languages, we propose supporting negative numbers in the second argument, making operations more intuitive by controlling the direction of elements being taken.With this enhancement, that example becomes simpler and clearer:
Here's how the negative number influences the direction of the second argument:
Limitations
This proposal is not currently backward compatible:
Therefore, we will conduct an impact assessment to evaluate the feasibility and ensure a smooth transition if this change is implemented.
Call for suggestions
We welcome any feedback or opinions on this proposal. Please share your thoughts by December 5, 2024. Your input is valuable as we prepare to begin active development on this initiative.
The text was updated successfully, but these errors were encountered: