eleventy icon indicating copy to clipboard operation
eleventy copied to clipboard

overriding `eleventyComputed`

Open btrem opened this issue 3 years ago • 1 comments

Suppose you specify an item in a directory data file with `eleventyComputed, e.g. in *.11tydata.js you have

module.exports = {
    eleventyComputed: {
        myItem: {
            foo: "defaultFoo",
            bar: "defaultBar"
        }
    }
};

and you want to override that item in a template file. You must use eleventyComputed there, as well. So,

---
myItem:
    foo: newFooValue
    bar: newBarValue
title: Post 2
---

does not work. But

---
eleventyComputed:
    myItem:
        foo: newFooValue
        bar: newBarValue
title: Post 3
---

Maybe that should be documented as a common pitfall. It took me quite a bit to figure out what I was doing wrong.

btrem avatar Sep 22 '22 23:09 btrem

There hasn't been any comments on this issue. Is 11ty working as it should in these cases, i.e., not a bug? If so, where should the documentation go? I'm happy to fork and contribute if that's deemed appropriate.

btrem avatar Aug 16 '23 23:08 btrem

I'm not an expert or the decider, but I think its working as expected (or at least behaving now I'd expect). If I understand the plumbing correctly eleventyComputed is computed slightly later in the data cascade, so it will override whatever values were set directly in the front matter. So if you're trying to set values in data files via eleventyComputed, you'd need to do that in the template as well. (There is also an override: prefix, but I've personally never needed/used it, and might be specific to data deep merge so may or may not apply here.)

pdehaan avatar Aug 22 '23 17:08 pdehaan