Make it easier to append and prepend items in arrays #1866
benjaminsehl
started this conversation in
Requests for Suggestions
Replies: 1 comment
-
yes, please make it easier to work with array. Also it would be nice to have unified arrays. For instance, product_list and collection_list setting in themes behave like array… but do not have any size attribute (for some reason it’s called count there, I mixed things all the time; having an alias would help a lot). Ideally we should be able to append elements to those objects as well. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Originally posted as issue #1851
Author: Shopify
Expected end date: December 5, 2024
Background
Handling arrays in Liquid is challenging.
Developers often need to convert arrays into strings, perform operations, and then split them back, relying heavily on the Liquid String API as it's more robust than the Array API.
Proposal
We should eliminate workarounds like string concatenation and splitting and make it easier to perform common tasks such as adding new items in an array. This will make Liquid templates simpler, less verbose, and more declarative.
To make that happen, we should support the
append
andprepend
filters in arrays. They will return a new array with the specified element added to the end or beginning, respectively.Limitations
This proposal is not backward compatible [1] [2].
Therefore, the implementation is pending an impact assessment. If we identify it's impossible to handle backward compatibility, we aim to introduce only the
append
functionality instead, using an unused filter name (e.g.add
).We're proposing the
append
/prepend
direction first because we consider this a more idiomatic and cohesive direction for the Liquid API.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.
Beta Was this translation helpful? Give feedback.
All reactions