This is a long topic and I’ll provide different information to fully describe a scenario. Please be patient and join if you really have something to say.
For years now I’ve used the most basic Pagination I’ve learned:
{{ range $offset, (.Paginator).Pages }}
Do something
{{ end }}
And it always worked. But now that I finally managed to create componentized Content Files with an “include” Shortcode I needed a way to filter out these pluggable pages that can be individually accessed, with their own URLs.
So I’ve added a “boolean” FrontMatter Parameter listed
in order to condition the range
:
{{ range $offset, (where (.Paginator).Pages ".Params.listed" "!=" "false") }}
Do something
{{ end }}
If the said Parameter doesn’t exist, as far as I could notice, it’s automatically considered a true
in the condition and it’s normally processed by the range
. But if it is set -AND- defined as false
, it’s filtered out.
This works as intended but produces an unwanted behaviour.
My Paginator is defined to have only 6 elements per page. Pages in which all elements are marked to be listed (i.e. do not have the Parameter), all 6 markups are perfectly rendered. But in pages in which one or more elements are marked to be skipped, there are “gaps” in the markup where these elements would be if not filtered.
That was kind of hard to understand, I admit, but, here, imagine a set of 13 posts like this:
|-\ Post #1
|-\ Post #2
|-\ Post #3
|-\ Post #4
|-\ Post #5
|-\ Post #6
|-\ Post #7
|-\ Post #8
|-\ Post #9
|-\ Post #10
|-\ Post #11
|-\ Post #12
|-\ Post #13
In a Paginator of 6 per page, that would give me 2 pages completely filled and one with just one entry. Perfect.
But let’s say Post #8 now must have the custom Parameter I’ve defined. Post #9 will then occupy its place but Post #13 from the last page WILL NOT occupy the last spot in the second page, I’ll remain with 3 pages and the second will have a “gap” without anything rendered.
And this happens to any Parameter-based conditional defined.
In a list-like Pagination, this isn’t noticeable. But in my theme, I use Bootstrap Cards to show a thumbnail for each entry followed by the Post Title / Summary and the problem does become noticeable.
Is there anything I could do on my end or this is a Hugo issue?