11ty / eleventy

A simpler site generator. Transforms a directory of templates (of varying types) into HTML.
https://www.11ty.dev/
MIT License
17.09k stars 494 forks source link

Cannot disable global pagination in template with 'override:pagination' #2292

Open JohJonker opened 2 years ago

JohJonker commented 2 years ago

Describe the bug I have a pagination key set up in my global data, so that it applies to all pages. I want to selectively disable pagination on specific 11ty.js templates. In a specific 11ty.js template frontmatter, I tried to set pagination to empty values, e.g. pagination: '', pagination: {}, and pagination: undefined but they are ignored due to the Data Cascade's Deep Merge. The Date Deep Merge page tells me I can override this Deep Merge behaviour for pagination by adding override:pagination to my 11ty.js template's frontmatter. However, when doing this and setting override:pagination to an empty value like above, I receive the following error:

"[11ty] > Misconfigured pagination data in template front matter (YAML front matter precaution: did you use tabs and not spaces for indentation?)."

To Reproduce Steps to reproduce the behavior:

  1. Set pagination globally to regular pagination values, e.g. { data: 'languages', size: '1', alias: 'language' }
  2. Set exports.data = { 'override:pagination': undefined } in test.11ty.js
  3. Run npm start
  4. See error

Expected behavior I'm hoping there's some way to override pagination in the 11ty.js data, but it looks like we might need to unset the 'pagination' key completely to disable it, which doesn't seem possible?

Alternatives I considered adding eleventyComputed to override pagination, but that's too late in the data cascade to change pagination.

Environment:

Additional context My use case in the above scenario is to use pagination to create multi-language versions of each template and collection (which is working very well), but I'm trying to opt out of this behaviour for pages that shouldn't be translated.

zachleat commented 2 years ago

Here’s the culprit here. The entire pagination key is opt-ed out of deep merge (for https://github.com/11ty/eleventy/issues/147#issuecomment-440802454 )

https://github.com/11ty/eleventy/blob/b46e32723f26a0f69df3a1a3097b070e86b29095/src/Template.js#L440-L444

The Data Deep Merge docs do note this:

Note that all data stored in the pagination variable is exempted from this behavior (we don’t want pagination.items to be merged together).

https://www.11ty.dev/docs/data-deep-merge/

All that said, I think we could have our cake and eat it too by adding a special case for falsy pagination maybe?