1.0.0-beta.1: eleventyComputed doesn't interpolate global data in front-matter arrays
AleksandrHovhannisyan opened this issue · comments
Describe the bug
If eleventyComputed
contains an array of objects (key-value pairs), and you try to interpolate global data inside one of the string values, it gets output literally as "{{ whatever }}"
rather than interpreted as the value of whatever
. That is, this doesn't work anymore:
---
eleventyComputed:
array:
-
key: "{{ variable }}"
---
This is working correctly on 0.12.1 but seems to have regressed when upgrading to beta 1.
To Reproduce
- Clone https://github.com/AleksandrHovhannisyan/11ty-sandbox
- Run
yarn
to install dependencies. - Check out the following branch:
eleventycomputed-arrays
. - Run
yarn serve
. - Observe two logs, one that works and another that doesn't.
The repo has two things: a data file (src/_data/data.js
) and a page (src/index.html
).
data.js
:
module.exports = {
dynamicValue: 42
};
index.html
:
---
eleventyComputed:
notArray: "{{ data.dynamicValue }}"
array:
-
staticKey: "static value"
dynamicKey: "{{ data.dynamicValue }}"
---
{{ notArray | log }}
{{ array | first | log }}
notArray
logs 42
correctly. The array log prints:
{ staticKey: 'static value', dynamicKey: '{{ data.dynamicValue }}' }
Expected behavior
The following should get logged:
{ staticKey: 'static value', dynamicKey: '42' }
On 0.12.1, this works as expected; the value gets interpolated in the string rather than interpreted literally. Example on my site where I do this: https://github.com/AleksandrHovhannisyan/aleksandrhovhannisyan.com/blob/master/src/_layouts/post.html#L9
Environment:
- Eleventy Version: 1.0.0-beta.1
Looks like this may be related to data deep merging getting enabled in v1.0.0. When I disable it (0.x
behavior), this test case passes:
eleventyConfig.setDataDeepMerge(false);
But that doesn't seem to be the desired behavior of deep merging (unless I misunderstood how it works), so this is a temporary fix.
Confirmed.
I’m not 100% sure that the YAML you provided there was accurate though or that this is related to data deep merge.
---
eleventyComputed:
notArray: "{{ data.dynamicValue }}"
array:
- "static value"
- "{{ data.dynamicValue }}"
---
{{ "not array" | log }}
{{ notArray | log }}
{{ "array" | log }}
{{ array | log }}
outputs
not array
42
array
[ 'static value', '{{ data.dynamicValue }}' ]
independent of data deep merge or not.
This will ship with 1.0.0-beta.3
Awesome, thank you!