Hi, I’m new to Jekyll and the liquid filter ‘limit’ seems to be not working, even on a simple array of numbers I used to test it.
{{ “1,2,3,4,5,6” | split: “,” | limit: 3 | size}} outputs ‘6’ and {{ “1,2,3,4,5,6” | split: “,” | limit: 3 }} outputs 123456. I’m intending to use it for the latest 3 blog posts but instead it just gives me all the posts.
The ‘sample’ filter seems to work correctly and limits the output to 3.
I did gem uninstall , bundle install, I don’t see a _plugins folder.
My environment details:ruby 3.4.4 (2025-05-14 revision a38531fd3f) +PRISM [arm64-darwin22]
gem version: 3.7.1
jekyll 4.4.1
There isn’t a limit filter in Liquid (for loops have a limit parameter, but that’s not a filter). Unfortunately, by default Jekyll’s Liquid does not flag unknown filters with a warning or error. You can turn on error reporting in your _config.yml by adding:
liquid:
strict_filters: true
Then, Liquid will produce an error like: Liquid Exception: Liquid error: undefined filter limit in...
You can use the slice filter to extract part of an array. For example:
{{ "1,2,3,4,5,6" | split: "," | slice: 0,3 }}
Thanks so much! I must have misread the loop structure and used limit outside of it. Slice works perfect, you’re a superstar.