Skip to content

How do I opt out of deep-data merging in data files? #2868

Open
@AleksandrHovhannisyan

Description

@AleksandrHovhannisyan

Description

The 11ty docs on opting out of data merging mention that you can use an override: prefix to opt out of merging data for a specific front-matter variable:

Use the override: prefix on any data key to opt-out of this merge behavior for specific values or nested values.

{
  "tags": ["posts"]
}
---
override:tags: []
---

Even though normally the posts/firstpost.md file would inherit the posts tag from the directory data file (per normal data cascade rules), we can override the tags value to be an empty array to opt-out of this behavior.

But how would I opt out of deep data merging for data files? For example, suppose I have this file: src/_data/data.js:

// src/_data/data.js
module.exports = {
  key: "value",
}

And later, somewhere in a directory, I want to override this data file:

// src/_collection/collection.11tydata.js
module.exports = {
  "override:data": {
    key: "new-value"
  }
}

Unfortunately, this doesn't work. Is this not supported, or do I need to use a different syntax?

Steps to repro

  1. Clone https://github.com/AleksandrHovhannisyan/11ty-sandbox/tree/merge-override
  2. Run yarn to install dependencies.
  3. Run yarn serve.
  4. Observe that { "key1": "value1", "key2": "value2" } is logged in the server console.
  5. Expectation: Only { "key2": "value2" } gets logged.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions