-
-
Notifications
You must be signed in to change notification settings - Fork 506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pagination size: 1 doesn't populate page arrays but returns single items #1372
Comments
I can replicate this bug. A temporary workaround is to wrap the items in square brackets to turn them in to array literals;
|
Thanks, but unfortunately what I posted is just a POC, I'd like to have it work in a collection-based pagination 😄 |
I just noticed this myself. It is explained in the docs:
But to me this is just wrong. The same code should work whether the size is 1 or 2+. |
I agree with @svivian, @onion2k and @SirePi that I would consider this a bug. Option 1Maybe an option to resolve this (because I see the good intention of leaving out the array for e.g. CMS provided data where you always use pagination 1) would be to insert a magic keyword that leaves out the array. So my proposal would be either: ---
pagination:
data: testdata
size: 1
alias: posts
testdata:
- itemkey1
- itemkey2
- itemkey3
--- would result in ---
pagination:
data: testdata
size: some_magic_string_which_might_be_unwrapped
alias: posts
testdata:
- itemkey1
- itemkey2
- itemkey3
--- would result in Option 2Another option would be to add a
This option might increase the implementation difficulty and the cognitive load for new users, but it would offer the benefit of making working with dictionary data even easier for experienced users. Of course naming is always up for debate. Maybe instead of using a format string, it would be useful to use "format modifiers" as a list, so you wouldn't write ---
pagination:
data: testdata
size: some_magic_string_which_might_be_unwrapped
alias: posts
format: objectArray
testdata:
- itemkey1
- itemkey2
- itemkey3
--- but you would write ---
pagination:
data: testdata
size: some_magic_string_which_might_be_unwrapped
alias: posts
format:
- object
- array
testdata:
- itemkey1
- itemkey2
- itemkey3
--- But this is probably too hard to document and maintain and keep in mind which format modifiers are compatible. I know this became a long comment, but I hope it becomes a startingpoint for a good debate. |
Hey @zachleat, I just want to push this bug (since it's one of the oldest open ones and v3 seems to be coming up). |
Ah—hmm. I don’t consider this to be a bug. It’s strictly limited to the use of |
Describe the bug
Setting size 1 in a pagination results in having a flat array instead of an array of arrays, as described in
To Reproduce
Use the following njk
Change size to a value greater than 1 to have the correct behavior
Expected behavior
I expected to see one item and 3 pages with size 1, but apparently it returns "itemkey1" directly, without wrapping it in an array, with the result of having each character treated as a single item instead.
Screenshots
![image](https://user-images.githubusercontent.com/5575967/90767167-0196ad80-e2ed-11ea-9c81-614299c89017.png)
OK (size 2)
NOT OK (size 1)
![image](https://user-images.githubusercontent.com/5575967/90767455-8bdf1180-e2ed-11ea-9ab3-1aec41d5f541.png)
Expected (size 1)
![image](https://user-images.githubusercontent.com/5575967/90767397-72d66080-e2ed-11ea-8b81-8c42ba7b245e.png)
Environment:
The text was updated successfully, but these errors were encountered: