hBy2Py
hBy2Py

Reputation: 1832

Does Jekyll suffer anywhere from the 50-item for-loop maximum declared by Shopify's Liquid specification?

The Shopify Liquid docs for the {% for %} loop tag declare that:

for loops can output a maximum of 50 results per page. In cases where there are more than 50 results, use the paginate tag to split them across multiple pages.

This question confirms that, as of four years ago, the 50-item limit was active in Shopify.


However, if I scratch together a Jekyll post with the content as:

.{% for var in (1..100) %} {{ var }} .{% endfor %}

it renders in the build as I would expect, including all integers from one to one hundred:

Screencap of rendered output

So, clearly at least some for loops in Jekyll aren't bound by this 50-item limit.

Is Jekyll completely free of this constraint? Or, are there some situations where for loops will unexpectedly get truncated at 50 items?

Upvotes: 0

Views: 169

Answers (1)

juzraai
juzraai

Reputation: 5943

No, Jekyll does not have this kind of limit.

  • According to Liquid documentation there are multiple versions of Liquid: "The most popular versions of Liquid that exist are Liquid, Shopify Liquid, and Jekyll Liquid." Jekyll's Liquid documentation simply links back to Liquid documentation which doesn't mention any built-in fixed limitation, that Shopify Liquid documentation does.
  • When I searched for this limit in conjunction with Shopify, I found many results about the built-in limit. But in conjunction with Jekyll, I can only find topics about applying a limit by hand - as the for loop in Jekyll is unlimited by default.
  • You showed an example of a for loop saying "some for loops" are unlimited. I can't think of any other kind of for loop, just maybe the ones which iterate a collection, like posts. So I created a Bash script which tests if Jekyll has that kind of limit. The script creates a new project, creates 1000 copies of the sample post, builds the site and counts the post links on the index page. (The index page of the default sample project lists all posts without pagination.) For me it returns 1000, which means Jekyll does not truncate the results at 50.

    #!/bin/bash
    N=1000
    F=2018-08-14-welcome-to-jekyll
    rm -rf limit-test
    jekyll new limit-test
    cd limit-test
    for i in $(seq 2 $N); do
      cp _posts/$F.markdown _posts/$F-$i.markdown
    done
    jekyll build
    grep "post-link" _site/index.html | wc -l
    # 1000
    

Upvotes: 1

Related Questions