access eleventyComputed data from another data file #3218
Replies: 3 comments 4 replies
|
is it possibile? |
|
More general question: is it possible to access data from another data file? _data/first.js
_data/second.js// first.js
export default function () {
return { foo: 'bar' };
}// second.js
```js
// first.js
export default function () {
// data ?
// this.data ?
return { baz: data.first.foo + ' baz' };
} |
|
Thinking through this a bit more, the answer is no, you can't get the result of a function from More correctly, you can't get the result of a function in This is because eleventyComputed is processed at the very end of the data cascade just before the template is rendered. So in your example above In Assume you have And And a template ---
layout: _page_skeleton.njk
title: "Homepage"
env: development
---
<p>{{ data1 }}</p>
<p>{{ data2 }}</p>You'll notice that But in the template All that said, what is the reason for wanted to access something from eleventyComputed from within another data js file? There is almost certainly a way of achiving the result you want using a different method. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hello,
in src/data I have two files:
inside eleventyComputed I have:
Ok, Can I access data2 in commonData.js? How? If I get eleventyComputed.data1 all it's ok and return data (static) but I I try data2 it return the function instead the result
thank you
All reactions