For-Loops Only Itterate Over 127 Elements
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 11.9k
- Forks
- 1.5k
- Avg merge
- 17h 55m
- Merged PRs (30d)
- 3
Description
I have a JSON file which contains a Liquid for-loop that loops over all the pages in my site. It looks like this:
---
---
[
{%- for pagei in site.pages -%} {
"title": "{{pagei.title}}" ,
"url": "{{pagei.url}}",
"dir": "{{pagei.dir}}",
"path": "{{pagei.path}}",
"name": "{{pagei.name}}",
"layout": "{{pagei.layout}}",
"author": "{{pagei.author}}",
"date": "{{pagei.date}}",
"pageRole": "",
"parent": "",
"parentInd": "",
"children": [],
"siblings": []
}{%- unless forloop.last -%},{%- endunless -%}
{%- endfor -%}
]
When this gets rendered into plain JSON, it only contains 127 of the site's pages, despite no such limit being specified in the loop.
I was able to work around this by specifying a limit equal to the number of pages. Though, this seems really redundant. It seems like the loop ought to know how many things it's iterating over, since that's already set in stone when the loop begins! My workaround looks like this:
---
---
[
{% assign npages = site.pages | size -%}
{%- for pagei in site.pages limit:npages -%} {
"title": "{{pagei.title}}" ,
"url": "{{pagei.url}}",
"dir": "{{pagei.dir}}",
"path": "{{pagei.path}}",
"name": "{{pagei.name}}",
"layout": "{{pagei.layout}}",
"author": "{{pagei.author}}",
"date": "{{pagei.date}}",
"pageRole": "",
"parent": "",
"parentInd": "",
"children": [],
"siblings": []
}{%- unless forloop.last -%},{%- endunless -%}
{%- endfor -%}
]
Sorry if this is a Jekyll problem rather than a Liquid problem. I don't know anything about the Ruby guts of either.
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
Start by reproducing the reported template with more than 127 pages, then trace how Liquid handles the for-loop over the collection. Confirm whether the loop truncates the collection without an explicit limit; done means all pages render without the workaround and a regression test covers the behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100