[request] make arrays in liquid / concat filter
Open
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 11.9k
- Forks
- 1.5k
- Avg merge
- 17h 55m
- Merged PRs (30d)
- 3
Description
Problem
- Not being able to make arrays in liquid.
- Simple tasks end up requiring multiple server requests for information.
- Memory limit is often exceeded when using workarounds.
Context
- This is often seen when nesting
forloops in template files (i.e. looping through articles then looping through article tag). - Because Shopify doesn't offer a way to build arrays, we can't optimize to one
forloop to create arrays.

Possible Solution
- The
concatfilter seems to be a possible solution. We can see thatconcatis concatenating hashes. If we could create arrays with this it would save a lot of requests from hitting the server.
Example of concat hashes
- Works great in specific situations: http://freakdesign.com.au/blogs/news/105090695-show-the-latest-shopify-articles-from-all-blogs.
Ideal fix
- We would like to be able use
concatto build an array. - We're not married to
concatas the solution but it seems like the closest available solution. - https://github.com/Shopify/liquid/blob/6434b8d2bb1cfabdd861bfc6f5be31c019171b82/lib/liquid/standardfilters.rb#L218

Current situation:
{% for article in blogs[settings.blog_widget_select].articles %}
{% for tag in article.tags %}
{% assign current_tag = tag | downcase %}
{% if current_tag == 'tag 1' %}
// print article
{% endif %}
{% endfor %}
{% endfor %}
{% for article in blogs[settings.blog_widget_select].articles %}
{% for tag in article.tags %}
{% assign current_tag = tag | downcase %}
{% if current_tag == 'tag 2' %}
// print article
{% endif %}
{% endfor %}
{% endfor %}
{% for article in blogs[settings.blog_widget_select].articles %}
{% for tag in article.tags %}
{% assign current_tag = tag | downcase %}
{% if current_tag == 'tag 3' %}
// print article
{% endif %}
{% endfor %}
{% endfor %}
{% for article in blogs[settings.blog_widget_select].articles %}
{% for tag in article.tags %}
{% assign current_tag = tag | downcase %}
{% if current_tag == 'tag 4' %}
// print article
{% endif %}
{% endfor %}
{% endfor %}
Ideal situation:
{% assign tag_1_articles = false %}
{% assign tag_2_articles = false %}
{% assign tag_3_articles = false %}
{% assign tag_4_articles = false %}
{% for article in blogs[settings.blog_widget_select].articles %}
{% for tag in article.tags %}
{% assign current_tag = tag | downcase %}
{% if current_tag == 'tag 1' %}
{% assign tag_1_articles = tag_1_articles | concat:article %}
{% endif %}
{% if current_tag == 'tag 2' %}
{% assign tag_2_articles = tag_2_articles | concat:article %}
{% endif %}
{% if current_tag == 'tag 3' %}
{% assign tag_3_articles = tag_3_articles | concat:article %}
{% endif %}
{% if current_tag == 'tag 4' %}
{% assign tag_4_articles = tag_4_articles | concat:article %}
{% endif %}
{% endfor %}
{% endfor %}
// print tag_1_articles
// print tag_2_articles
// print tag_3_articles
// print tag_4_articles
CC: @NathanPJF
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read lib/liquid/standardfilters.rb around line 218 to understand the existing concat behavior, then examine how Liquid represents arrays and hashes in filters. The work is done when a documented, tested approach lets concat build arrays as shown in the issue, or the supported alternative is clearly established.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100